Curiously, there are two very similar methods, interrupted and isInterrupted. The interrupted method is a static method that checks whether the current thread has been interrupted. (Recall that a thread is interrupted because another thread has called its interrupt method.) Furthermore, calling the interrupted method resets the "interrupted" status of the thread. On the other hand, the isInterrupted method is an instance method that you can use to check whether any thread has been interrupted. Calling it does not change the "interrupted" status of its argument.
It is a bit tedious that there are two distinct ways of dealing with thread interruption—testing the "interrupted" flag and catching the InterruptedException.
It would have been nice if methods such as sleep had been defined to simply return with the "interrupted" flag set when an interruption occurs—then one wouldn't have to deal with the InterruptedException at all. Of course, you can manually set the "interrupted" flag when an InterruptedException is caught:
Don't do that! Either set the "interrupted" flag of the current thread, or propagate the exception to the calling method (and ultimately to the run method).
If you don't want to clutter up lots of nested methods with isInterrupted tests, you can turn the "interrupted" flag into an exception.
if (isInterrupted()) throw new InterruptedException();
Assuming that your code is already prepared to terminate the run method when an InterruptedException is thrown, this is a painless way of immediately terminating the thread when an interruption is detected. The principal disadvantage is that you have to tag your methods with
throws InterruptedException
since, alas, the InterruptedException is a checked exception.