acquireSharedInterruptibly
生活随笔
收集整理的这篇文章主要介绍了
acquireSharedInterruptibly
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
countdownlatch也用到了AQS,在CountDownLatch内部写了一个Sync并且继承了AQS这个抽象类重写了AQS中的共享锁方法。首先看到下面这个代码,这块代码主要是判断当前线程是否获取到了共享锁;(在CountDownLatch中,使用的是共享锁机制,因为CountDownLatch并不需要实现互斥的特性)
public final void acquireSharedInterruptibly(int arg) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); if (tryAcquireShared(arg) < 0) //state如果不等于0,说明当前线程需要加入到共享锁队列中 doAcquireSharedInterruptibly(arg); }
总结
以上是生活随笔为你收集整理的acquireSharedInterruptibly的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Condition总结-CountDow
- 下一篇: CountDownLatch.count