Git Product home page Git Product logo

Comments (9)

lycying avatar lycying commented on June 3, 2024

说实在的,我也很讨厌面试这种源码级别的问题,没啥鸟用,也考验不出来应聘者的实际水平。董源码难道就代表技术好?不过bat都是这么面的。所以你只能适应。

from interview-ng.

lycying avatar lycying commented on June 3, 2024

用面试的话来说就是、筛选一下、懂原理的优先。矮个子里面挑高个子

from interview-ng.

lycying avatar lycying commented on June 3, 2024

我觉得还是要以线上优化,线上问题的解决方案,项目的技术架构设计为主要面试目的。

from interview-ng.

lycying avatar lycying commented on June 3, 2024

来正文:公平锁指的是按照线程请求的顺序,来分配锁;而非公平锁指的是不完全按照请求的顺序,在一定情况下,可以允许插队。

from interview-ng.

lycying avatar lycying commented on June 3, 2024

公平与否,是由底层的Sync实现的,有FairSync和NonfairSync之分,而Sync是继承的AQS。这两种锁的唯一区别,就是公平锁在获取锁的时候,要先判断等待队列中是否已经有线程排队了。如果有的话,公平锁对应的线程就不再尝试获取锁。

from interview-ng.

lycying avatar lycying commented on June 3, 2024

image
看代码就知道了,但很多人不会看。这里直接贴出来。

from interview-ng.

lycying avatar lycying commented on June 3, 2024

接下来还可能会有连环问:是抢占式性能高还是公平的呢?

抢占式的话你不用在队列里面记录他的顺序、直接开门放闸随便抢,谁抢到是谁的。 公平锁你要记录排队的顺序。
所以:公平锁吞吐量会低一些,但非公平锁有可能会发生线程饿死的情况。

from interview-ng.

lycying avatar lycying commented on June 3, 2024

那用在什么地方呢?

我们平常使用的锁,是非公平锁。所以只说公平锁的场景。

如果你有顺序性要求,就可以使用公平锁。非要举个例子的话,可以描述下抽奖系统,按照先后来。

from interview-ng.

lycying avatar lycying commented on June 3, 2024

http://xjjdog.cn/interview/16074172101863.html

from interview-ng.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.