0
try{...}
catch(InterruptedException e)
{  }

I wonder what happen after InterruptedException is thrown

is thread interrupted status set to true or not ?

das kinder
  • 1,180
  • 2
  • 10
  • 16
  • possible duplicate of [Handling InterruptedException in Java](http://stackoverflow.com/questions/3976344/handling-interruptedexception-in-java) – Gray Mar 03 '14 at 19:38

1 Answers1

3

It depends on what throws the InterruptedException. But the good practice, followed by methods of the JDK, is to clear the interrupt status when the exception is thrown.

See Object.wait() for example:

if any thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • All JDK methods that throw `InterruptedException` that I know of behave the same as `Object.wait()`. i.e. The interrupt bit is cleared when the exception is thrown. That's why we need to re-interrupt the thread in the catch. – Gray Mar 03 '14 at 19:42
  • @Gray: what I wanted to point out is that you're free to throw the exception yourself, but it doesn't automatically clear the interrupt status. The JDK methods consistently clear it before throwing the exception. – JB Nizet Mar 03 '14 at 19:45
  • I figured @JB. I just wanted to more specific about it. – Gray Mar 03 '14 at 19:46