Thread unpark, park and interrupt

java

unpark/park/interrupt

unpark and park are Unsafe methods to unblock and unschedule threads.

Both are always used with LockSupport. AbstractQueuedSynchronizer leverages the methods to implement lock. It’s the native way to hang up threads. 3 things should be noted:

  1. If a thread is unparked, following call to park will not hang up the thread.
  2. If a thread is interrupted, following call to park will not hang up the thread. That’s why interruptible lock can be implemented.
  3. If a thread is parked and then subsequently interrupted, the thread will be awakened from its parked state.