Java線程狀態中BLOCKED和WAITING有什麽差別?
剛才在看CSDN的問答時。發現這個問題。
原問題的作者是在觀察jstack的輸出時提出的疑問。那麽BLOCKED和WAITING有什麽差別呢?
答復在JDK源代碼中能夠找到,例如以下是java.lang.Thread.State類的一部分凝視。
/**
* 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
* [email protected]
*/
BLOCKED,
/**
* Thread state for a waiting thread.
* A thread is in the waiting state due to calling one of the
* following methods:
* [email protected] Object#wait() Object.wait} with no timeout
* [email protected] #join() Thread.join} with no timeout
* [email protected]