Comments (9)
说实在的,我也很讨厌面试这种源码级别的问题,没啥鸟用,也考验不出来应聘者的实际水平。董源码难道就代表技术好?不过bat都是这么面的。所以你只能适应。
from interview-ng.
用面试的话来说就是、筛选一下、懂原理的优先。矮个子里面挑高个子
from interview-ng.
我觉得还是要以线上优化,线上问题的解决方案,项目的技术架构设计为主要面试目的。
from interview-ng.
来正文:公平锁指的是按照线程请求的顺序,来分配锁;而非公平锁指的是不完全按照请求的顺序,在一定情况下,可以允许插队。
from interview-ng.
公平与否,是由底层的Sync实现的,有FairSync和NonfairSync之分,而Sync是继承的AQS。这两种锁的唯一区别,就是公平锁在获取锁的时候,要先判断等待队列中是否已经有线程排队了。如果有的话,公平锁对应的线程就不再尝试获取锁。
from interview-ng.
from interview-ng.
接下来还可能会有连环问:是抢占式性能高还是公平的呢?
抢占式的话你不用在队列里面记录他的顺序、直接开门放闸随便抢,谁抢到是谁的。 公平锁你要记录排队的顺序。
所以:公平锁吞吐量会低一些,但非公平锁有可能会发生线程饿死的情况。
from interview-ng.
那用在什么地方呢?
我们平常使用的锁,是非公平锁。所以只说公平锁的场景。
如果你有顺序性要求,就可以使用公平锁。非要举个例子的话,可以描述下抽奖系统,按照先后来。
from interview-ng.
http://xjjdog.cn/interview/16074172101863.html
from interview-ng.
Related Issues (10)
- spring中,以 Aware结尾的类,都是干什么用的?能举例说明么? HOT 4
- 【Spring】Springboot常用的注解有哪些?如果这些注解错位会发生什么? HOT 1
- HashMap如何根据Key的自然排序输出?Value呢? HOT 6
- redis分布式锁与zk分布式锁区别 HOT 4
- mysql的索引有哪些种类,使用了什么样的数据结构,为什么要使用这种结构 HOT 3
- 【!】业务服务 和 后台管理服务 DAO层如何处理, 共用pom依赖、分别写、抽取数据查询服务 HOT 4
- ThreadLocal的原理和内存泄漏的原因, InheritableThreadLocal用过吗和ThreadLocal的区别 HOT 7
- 【Kafka】使用Kafka,如何保证消息不丢? HOT 3
- 【MySQL】Redolog,Undolog和Binlog的区别
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from interview-ng.