For example:
public synchronized Object get() {
while (result == null) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
// Do we own the monitor of this object?
}
}
return result;
}
When e.printStackTrace()
executes, are we guaranteed to own the object's monitor?
The reference says that when wait()
returns after a notify()
or notifyAll()
call, the thread waits until it acquires the object's monitor. But what about the case when wait()
throws an exception?
java.util.concurrent.*
) that are better suited for making threads communicate and coordinate with each other. – Umbles