The difference between Java thread state blocked and the waiting

The difference between Java thread state blocked and the waiting

BLOCKED state

Scene thread is in the BLOCKED state .
The current thread to wait for a monitor lock, such as waiting to perform synchronized code block or to use labeled synchronized.
In the synchronized block called circulating type Object wait method
below show some 样例.

synchronized(this)
{
	while (flag)
	{
		obj.wait();
	}
// some other code
}

WAINTING state

Scene thread is in the WAITING state.

Object method calls the object's wait, but do not specify a timeout value.
Call Thread object join method, but does not specify a timeout value.
Call park method LockSupport object.

TIME_WAINTING state

Scene thread is TIMED_WAITING state.

Thread.sleep method call.
Object object invocation of the wait method, specify a timeout value.
Call join method of the Thread object, specify a timeout value.
Call parkNanos method LockSupport object.
Call parkUntil method LockSupport object.

Published 47 original articles · won praise 8 · views 30000 +

Guess you like

Origin blog.csdn.net/nanchengyu/article/details/104895669