被阻塞的线程唤醒后的逻辑
生活随笔
收集整理的這篇文章主要介紹了
被阻塞的线程唤醒后的逻辑
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前面在分析await方法時,線程會被阻塞。而通過signal被喚醒之后又繼續回到上次執行的邏輯中標注為紅色部分的代碼
checkInterrupt WhileWaiting這個方法是干嘛呢?其實從名字就可以看出來,就是ThreadA在condition隊列被阻塞的過程中,有沒有被其他線程觸發過中斷請求
public final void await() throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); Node node = addConditionWaiter(); int savedState = fullyRelease(node); int interruptMode = 0; while (!isOnSyncQueue(node)) { LockSupport.park(this); if ((interruptMode = checkInterruptWhileWaiting(node)) != 0) break; } if (acquireQueued(node,savedState) && interruptMode != THROW_IE) interruptMode = REINTERRUPT; if (node.nextWaiter != null) //clean up if cancelled unlinkCancelledWaiters(); if (interruptMode != 0) reportInterruptAfterWait(interruptMode); }?
總結
以上是生活随笔為你收集整理的被阻塞的线程唤醒后的逻辑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AQS.transferForSigna
- 下一篇: checkInterruptWhileW