The simplest solution would be to use a LinkedBlockingQueue<
String> instead of a List. But to answer your question...
When the producer calls notifyAll(),
every waiting consumer wakes up. One of them gets the lock, empties the list, and releases the lock. Then another gets the lock, tries to empty the list, and fails. Finally, the third consumer does the same.
Making this worse is that wait() can return without notifyAll() being called at all.
To do this properly, you can use a while loop instead of an if statement:
Or use a BlockingQueue:
[ July 29, 2008: Message edited by: Carey Evans ]