posted 17 years ago
Hi,
Please read the sequence carefully. When notifyAll() is called, all the three threads will be notified. All the 3 threads will come out of wait state. So, all of them will try to execute the synchronized method at the same time. But since the method is synchronized, only one thread will be able to execute it at a time. After one thread finishes the method and releases the lock, the second thread will start & the third thread will enter the method after 2nd thread finishes the method.
Please note:
When multiple threads are ready to execute a method which is synchronized, only one thread which gets the lock first will be able to enter the method and the other threads will wait for the currently holding thread to release the lock. The most important point here is the wait here does not require a notify() to be called.
Hope this helps.