Taken from Heller et al's 4th ed (modified).
I have a
thread (which loops) that does a wait() for a Mailbox object to have a message associated with it. When a message is there, it spews the message to the console.
The user running is prompted (in a loop in the main thread) to enter a message and press Enter. Once he presses Enter, a storeMessage() method is run which does a notify();
I was trying to hand code the Mailbox example using wait() and notify() I found that I got the following output:
Question: I can see what's missing in the code (because I kinda copied Heller's example and just commented out the stuff I forgot), but what exactly does the commented out stuff do?
btw, I added the sleep() in the retrieveMessage() because I had some intuition that something might not work, and this output proves it.