When a thread t
calls the wait()
method on an object u
, it goes to the WAITING state until another thread calls notify()
on the same object u
OR another thread calls the interrupt()
method on the waiting thread t
. Taking into account that a waiting thread does not consume CPU cycles, how is it possible for the waiting thread to check the interrupted status within wait()
and throw an InterruptedException
?
That is, I imagine the following code within wait()
:
if (Thread.interrupted()) // Clears interrupted status!
throw new InterruptedException();