More Than Five More Than Five - 1 year ago 73
Java Question

Difference between WAIT and BLOCKED thread states

What is the difference between thread state WAIT and thread state BLOCKED?

The Thread.State documentation:


A thread that is blocked waiting for a monitor lock is in this state.


A thread that is waiting indefinitely for another thread to perform a particular action is in this state

does not explain the difference to me.

Answer Source

A thread goes to wait state once it calls wait() on an Object. This is called Waiting State. Once a thread reaches waiting state, it will need to wait till some other thread notify() or notifyAll() on the object.

Once this thread is notified, it will not be runnable. It might be that other threads are also notified(using notifyAll()) or the first thread has not finished his work, so it is still blocked till it gets its chance. This is called Blocked State.

Once other threads have left and its this thread chance, it moves to Runnable state after that it is eligible pick up work based on JVM threading mechanism and moves to run state.