See this other answer, which links to a very good discussion of interrupts. The main idea is that you should throw the InterruptedException
, except where it is impossible. If it's impossible, you should reset the interrupted status by calling Thread.currentThread().interrupt()
.
Why might it be impossible to rethrow the interrupted exception? You might be calling Thread.sleep()
inside the run()
method of a class that implements Runnable (which it doesn't look like you are). Because InterruptedException is checked and the run method is not declared to throw any exceptions in the Runnable interface, you cannot rethrow the exception. In that case, it is best to reset the interrupted status, and many containers that use Runnable will handle that properly.
In any case, you're doing the right thing by changing the code so it doesn't swallow the exception.