Java Concurrency Interview

Threads and lifecycle question 3 of 180 mid

What actually happens when you call interrupt() on a thread?

interrupt() sets an internal flag. If the thread is parked in an interruptible call such as sleep, wait, join, BlockingQueue.take or Lock.lockInterruptibly, the call throws InterruptedException and the flag is cleared as part of throwing. If the thread is running, nothing observable happens until it checks Thread.interrupted() or isInterrupted(), or reaches a blocking call.

Some blocking is not interruptible: acquiring synchronized, Lock.lock(), and most plain socket or file I/O. InterruptibleChannel is the exception, closing itself and throwing ClosedByInterruptException.

interruption

Quiz yourself on Threads and lifecycle Suggest a correction