Please enable JavaScript.
Coggle requires JavaScript to display documents.
5.4 Blocking & Interruptible Methods - Coggle Diagram
5.4 Blocking & Interruptible Methods
Reasons for Thread Blocking
Waiting for I/O completion
Waiting to acquire a lock
Thread.sleep (timed waiting)
Waiting for computation result from another thread
Blocked threads are placed in one of the blocked states:
BLOCKED
WAITING
TIMED_WAITING
Unblocking occurs when an external event happens, returning the thread to RUNNABLE state.
Blocking Methods & InterruptedException
BlockingQueue methods (put, take) throw InterruptedException
Other methods like Thread.sleep also throw it
InterruptedException signals that a method is blocking and can stop early when interrupted
Thread Interruption Mechanism
Thread.interrupt() used to interrupt a thread or check if it was interrupted
Each thread has an "interrupted" status
Interruption is cooperative (Thread A requests Thread B to stop but cannot force it)
Best use of interruption: Cancelling long-running tasks
Handling InterruptedException
Two main approaches:
Propagate the exception (if possible)
Either don’t catch it, or rethrow it after minor cleanup
Restore the interrupt status (if you can’t rethrow)
Use Thread.currentThread().interrupt();
What NOT to do:
Do NOT catch InterruptedException and ignore it (hides interruption from higher-level code)
Only acceptable to ignore if you control the entire thread (e.g., extending Thread class)