Only a few, well-defined “blocking methods” are interrupted. If the thread is interrupted, the flag is set, but nothing will happen until the thread reaches one of these well-defined breakpoints.
For example, calls to read() and write() are interrupted if they are called in threads created using the InterruptibleChannel . If Socket used as the starting point, the interrupt() call on Thread blocked in reading does not affect. Please note that if the blocking I / O operation is aborted successfully, the main channel is closed.
Another large class of intermittent operations are those performed by various class locking operations in java.util.concurrent packages. Of course, the original wait() method is also interrupted.
Lock methods can be identified by looking for throws InterruptedException in their method signatures. They should also be well documented to describe any side effects of interruption.
You can write your own intermittent method, but it should consist of intermittent lower-level operations.
source share