When an Thread.interrupt()
is called on some thread, what happens to that thread?
The target thread is "interrupted". Mostly, a flag is set in that thread, which the thread can look at (with Thread.interrupted()
). If the target thread was currently blocked on some I/O or Object.wait()
, then it is awakened with, respectively, an InterruptedIOException
or an InterruptedException
.
Thread interruption is a gentle way to nudge a thread. It is used to give threads a chance to exit cleanly, as opposed to Thread.stop()
, which is more like shooting the thread with an assault rifle.
The Javadoc for that method explains what happens in what situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With