Can someone please explain me the difference between Sleeping
, Wait
, Park
, and Monitor
thread states in VisualVM.
I found a very nice diagram which pretty much describes all you need/want to know.
The thread is in new state if you create an instance of Thread class but before the invocation of start() method.
The thread is in runnable state after invocation of start() method, but the thread scheduler has not selected it to be the running thread.
The thread is in running state if the thread scheduler has selected it.
Timed waiting is a thread state for a thread waiting with a specified waiting time. A thread is in the timed waiting state due to calling one of the following methods with a specified positive waiting time:
This is the state when the thread is still alive, but is currently not eligible to run.
A thread is in terminated or dead state when its run() method exits.
Hopefully this answers your question :).
Parking:
Disables the current thread for thread scheduling purposes unless the permit is available.
Threads are being parked or suspended if you like to call it this way because it does not have a permission to execute. Once permission is granted the thread will be unparked and execute.
Permits of LockSupport are associated with threads (i.e. permit is given to a particular thread) and doesn't accumulate (i.e. there can be only one permit per thread, when thread consumes the permit, it disappears).