In the statement below, the wait()
method is executed even though no notify is called but the statement below wait()
are executing only after
You don't need to postulate a spurious wakeup to explain what's going on here. When laurel terminates it sends a notifyAll to the threads that are waiting on it. (This is how Thread.join works.)
See the api doc for Thread#join:
This implementation uses a loop of this.wait calls conditioned on this.isAlive. As a thread terminates the this.notifyAll method is invoked. It is recommended that applications not use wait, notify, or notifyAll on Thread instances.
Also, always wait in a loop, using a condition; see the Oracle concurrency tutorial, especially the Guarded Blocks page. (From the description you can see join waits in a loop where the tested condition is isAlive on the thread joined to, so it is s good example. You can find the join method in the jdk source for the Thread class.)