Riordon

  博客园 :: 首页 :: 新随笔 :: :: :: 管理 ::

Java线程状态:BLOCKED与WAITING的区别

Doc说明:

/**
* Thread state for a thread blocked waiting for a monitor lock.
* A thread in the blocked state is waiting for a monitor lock
* to enter a synchronized block/method or
* reenter a synchronized block/method after calling
* {@link Object#wait() Object.wait}.
*/
BLOCKED,

/**
* Thread state for a waiting thread.
* A thread is in the waiting state due to calling one of the
* following methods:
*


    *
  • {@link Object#wait() Object.wait} with no timeout

  • *
  • {@link #join() Thread.join} with no timeout

  • *
  • {@link LockSupport#park() LockSupport.park}

  • *

*
*

A thread in the waiting state is waiting for another thread to
* perform a particular action.
*
* For example, a thread that has called Object.wait()
* on an object is waiting for another thread to call
* Object.notify() or Object.notifyAll() on
* that object. A thread that has called Thread.join()
* is waiting for a specified thread to terminate.
*/
WAITING,

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

posted on 2016-08-16 09:52  Riordon  阅读(2164)  评论(0)    收藏  举报