Thread
's javadoc states that Thread.notifyAll()
is called internally when thread finishes:
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.
As you can see, it's not recommended to use this feature, your code can be rewritten as follows:
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
Given the fact that this statement only appeared in Java 7 javadoc and it's recommended not to use this functionality, it looks like this behavior used to be an implementation detail of Thread
class, but people began to rely on it, so that language authors had to document it.