Suppose I have the following situation:
synchronized void someMethod() {
...
try {
wait();
}catch(InterruptedException e) {
System.out.println("InterruptedException caught");
}
...
}
and
synchronized void someOtherMethod() {
...
notify();
}
And the Thread
accesses first someMethod
, goes into wait
and then someOtherMethod
notifies it and returns to Runnable
state. Does the position of the notify()
call in the method matter? I noticed no change in behavior even when I positioned the notify()
call at different positions inside the method.
Shouldn't the Thread
be notified immediately when the call to notify()
is made?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…