Hi All,
Please help with this question from Dan's mock exam on
Thread's (Exam d Q.no 4)
Q:Which of the following occurs after invoking the interrupt method on a thread that is blocking due to a previous invocation of the join, sleep or wait method?
a.The thread moves into the Not-Runnable state.
b.The thread moves out of the Not-Runnable state.
c.An InterruptedException is thrown when the thread moves into the running state.
d.Calling Thread.interrupted after the InterruptedException is thrown will return true.
e. None of the above.
The answers are b & c
All i know is, interrupt works differently depending on what the thread is doing presently. When the InterruptedException is thrown it clears the interrupt flag.
When invoked interrupt() method with thread being in waiting state because of sleep() method, moves the thread from not-runnable state to runnable state throwing the Interrupted exception.
When thread is in waiting state because of wait() method, invoking the interrupt() method makes the thread move out of not-runnable state to ready state throwing the interrupted exception. This thread can get back to running state only when it is able to get a CPU cycle.
When the thread is in waiting state because of invocation of join(), it causes the thread to come out of the waiting state, throws the interrupted exception proceeding to the dead state.
If my understanding about the behavior of interrupt is right then the option
'C' is not valid as same behavior cannot be generalized for join(), sleep() and wait() with interrupt.
Plz help me with this
Reshma