Could you explain what
Thread.interrupt() sets the interrupted status/flag of the target thread. Then code running in that target thread MAY poll the interrupted status and handle it appropriately. Some methods that block such as
Object.wait() may consume the interrupted status immediately and throw an appropriate exception (usually
Interruption in Java is not pre-emptive. Put another way both threads have to cooperate in order to process the interrupt properly. If the target thread does not poll the interrupted status the interrupt is effectively ignored.
Polling occurs via the
Thread.interrupted() method which returns the current thread's interrupted status AND clears that interrupt flag. Usually the thread might then do something such as throw InterruptedException.
EDIT (from Thilo comments): Some API methods have built in interrupt handling. Of the top of my head this includes.
InterruptedException, instead using
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() that is more like shooting the thread with an assault rifle.