Subhasis Gorai wrote:
But who notifies the waiting thread(the calling thread), I mean is there any hook which gets executed as soon as the joining thread finishes its execution(job execution) and calls the notify()/notifyAll() on the joining thread? Or is it the combination of "Spurious wake up" and while(isAlive()) that works? Please clarify.
Thanks,
When a thread completes (returns or exceptions from run() method), it goes into code that cleans up after the thread. One of the operations is a notifyAll() method call on the newly completed thread's Thread object.
This is also why
you should not use a thread's Thread object for notification, as you will be sharing the notification object.
Henry