I'm new to the Java world, so bear with me if this is a stupid question.
I recently saw this code in the run () method of a Runnable.
try { if (Thread.interrupted()) { throw new InterruptedException(); } // do something if (Thread.interrupted()) { throw new InterruptedException(); } // do something if (Thread.interrupted()) { throw new InterruptedException(); } // and so on } catch (InterruptedException e){ // Handle exception } finally { // release resource }
How often and where should you check for thread interruption, which is good practice for it?
source share