美文网首页
BLOCKED VS WAITING

BLOCKED VS WAITING

作者: LordZhou | 来源:发表于2017-03-06 18:24 被阅读0次

BLOCKED - this state represents a thread which has been blocked and is waiting for a moniotor to enter/re-enter a synchronized block/method. A thread gets into this state after calling Object.wait method.
WAITING - this state represnts a thread in the waiting state and this wait is over only when some other thread performs some appropriate action. A thread can get into this state either by calling - Object.wait (without timeout), Thread.join (without timeout), or LockSupport.park methods.

BLOCKED是指线程正在等待获取锁;WAITING是指线程正在等待其他线程发来的通知(notify),收到通知后,可能会顺序向后执行(RUNNABLE),也可能会再次获取锁,进而被阻塞住(BLOCKED)。

PS:
notify与notifyAll的区别
notify是将某个waiting的线程状态改变为blocked(由于notify的线程尚未退出临界区,尚未释放锁,所以被唤醒的线程状态变为blocked),notifyAll是将所有线程的状态改变为blocked。

相关文章

网友评论

      本文标题:BLOCKED VS WAITING

      本文链接:https://www.haomeiwen.com/subject/abhugttx.html