What happens when a thread is interrupted when wait () is blocked?

Considering the fact that wait () can only be called in a synchronized context, which subsequently frees the monitor until notify / nofityAll is called on the same object by another thread,

Suppose Thread A blocks wait (), with the result that Thread B gets a lock. Now, if we interrupt Thread A, will control be immediately transferred to Thread A? in this case, since the catch try block that handles InterrupException is in a synchronized context, and since only one thread can hold the monitor at a time, what will happen to Thread B? should it go into a locked state until Thread A completes execution?

Thanks at Advance

+5
source share
2 answers

Reading the documentation really helps:

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait%28long%29

Thus, when a thread is interrupted, it must re-acquire the object's monitor in order to restore the synchronization state before an exception is thrown. The same applies to returning from a waiting (long) call after a specified period of time.

T . ; , - ante, wait. wait. , , thread T , wait.

, , InterruptedException. , .

+8

, A runnable, , , catch. B . , , , , , ; B A reacquire .

+2

All Articles