This code relies on an implementation detail that was not documented before Java 7, and now is (in the documentation of the join()
method), but with the following words:
As a thread terminates the this.notifyAll method is invoked. It is recommended that applications not use wait, notify, or notifyAll on Thread instances.
So I don't know where this question was asked, but it really tests if you know the hidden corner-cases of threading, that you should never use in any sane program.