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