Taken from K&B(with some added system outs).
1. If you comment out notifyAll(), all Reader threads comes back with the results; I'd have thought all Reader threads would be stuck waiting to be notified.
2. If you have notify(), instead of notifyAll() I'd expect one of the 3 Reader threads come back with results; but again none of the threads seem to have been blocked.
Can I have some explanation please or am I talking some nonsense?
What you are seeing is a side affect of the implementation of the join() method. The join() method simply checks the thread's alive flag, and if it is, it will just wait() on the thread object.
On the other side, when a thread completes (finishes the run() method), it does some internal cleanup -- to shutdown and cleanup after the thread. One action that it does is to send a notifyAll() on the thread object. This is so that threads that are trying to join() with this thread, can wake up and continue.
Henry
[ October 26, 2006: Message edited by: Henry Wong ]