Skip to content
Advertisement

Java Thread Sleep and Interrupted Exception

  1. Why does a sleep thread need a try catch to catch Interrupted Exception?
  2. Why does a sleep even emit an Interrupted Exception error?
    This are the two questions I really wanna find out about in java programming
    I’ve been searching through google and i’ve still haven’t found a clear explanation is to why this two things happen.

Advertisement

Answer

  1. Because a Thread cant complete its normal execution if you Interrupt it, and you need to catch that in order to be prepared to do something.
  2. Because a thread waiting is different from an interrupted thread, a thread waiting can be resumed, but an interrupted thread is already finish execution.
1 People found this is helpful
Advertisement