Understanding java.lang.Thread.State: WAITING (parking)

Permit means a permission to continue execution. Parking means suspending execution until permit is available.

Unlike Semaphore's permits, 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).

You can give permit to a thread by calling unpark(). A thread can suspend its execution until permit is available (or thread is interrupted, or timeout expired, etc) by calling park(). When permit is available, the parked thread consumes it and exits a park() method.


As per the java Thread State Documentation, A thread can go to WAITING state for three reasons:

  1. Object.wait with no timeout
  2. Thread.join with no timeout
  3. LockSupport.park

When you call a park method on a Thread, it disables the thread for thread scheduling purposes unless the permit is available. You can call unpark method to make available the permit for the given thread, if it was not already available.

So, when your Thread is in WAITING mode by LockSupport.park, it will show you as WAITING (parking).

Please make note that, you can call park on current Thread only. This is very helpful mechanism to implement Producer-Consumer Design Pattern.