当前位置:网站首页>BlockingQueue, synchronousqueue, arrayblockingqueue, reentrantlock, semaphore, fair and unfair

BlockingQueue, synchronousqueue, arrayblockingqueue, reentrantlock, semaphore, fair and unfair

2022-06-10 08:56:00 Wind chime peak

BlockingQueue Yes ReentrantLock Of the two Condition. A concern is not empty ,put If it is not empty, it will execute signal, You can go on take,take If time is empty , Will execute await. One cares whether it is full ,take If you are dissatisfied, you will execute signal, You can go on put,put If the time is full , Will execute signal.

SynchronousQueue By internal queues (TransferQueue, Corresponding to the fair strategy ) Or stack (TransferStack, Corresponding to unfair strategies ) Storage elements , The default is unfair policy , and ArrayBlockingQueue By an internal array of objects ,LinkedBlockingQueue Rely on the internal two-way linked list ,Node There is prev and next.

put after LockSupport.park,take after LockSupport.unpark. perhaps take after LockSupport.park, perhaps put after LockSupport.unpark.

SynchronousQueue May refer to :https://www.jianshu.com/p/fce6fbc155fa

ArrayBlockingQueue Default is not fair , Fairness and unfairness are reflected in ReentrantLock Is it fair or unfair .

ReentrantLock The fairness of 、 The unfairness lies in whether to rob the lock when there are nodes in the queue , Fair locks do not rob , Guarantee first come first served , Unfair will try to acquire the lock .

Semaphore The fairness of 、 Unfairness lies in acquire Whether you care about the nodes in the queue , In a fair case, a node in the queue will be suspended directly , Unfair will try to make AQS Of state-1.

原网站

版权声明
本文为[Wind chime peak]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100847457973.html