Hi all,
I've been very surprised when I knew a strange behavior of wait() function. The documentation of Object.wait() says:
Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
But below we can read:
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) {
while (<condition does not hold>)
obj.wait();
... // Perform action appropriate to condition
}
Does it mean that all the code that I wrote without condition loop is unreliable???
Could anyone familiar with a VM explain the cases when a spurious wakeup may occur?
Why not the logic above (condition loop) was implemented inside the wait() functions?
Anton