This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Basically, each of the first three threads started by this program will acquire a lock on w (the Waiting2 instance), print out its thread ID (some integer value), and then wait for a notification on w (giving up the lock while waiting). The fourth thread also acquires a lock on w, but does not produce any output. Instead, it will send a notification to wake all the previous threads. Each of the previous threads will then re-acquire the lock on w in some unknown order, and print its thread ID again before terminating.
The net result of this is that you should see exactly three different thread IDs in the output, with each ID occurring twice (once among the first three numbers, then again among the last three numbers). The order in which these thread IDs appear is not fixed, since you can't predict the order in which the threads will re-acquire w's lock.
Based on the above analysis, the correct answers are "6 7 8 6 7 8" and "6 7 8 8 6 7". Note that the thread IDs don't necessarily have to appear in ascending order among the first three numbers. So if "8 7 6 7 8 6" were one of the available options, it would have been a valid answer too. [ October 31, 2007: Message edited by: Kelvin Lim ]
Joined: Mar 23, 2007
That's a very nice explanation
Kelvin Chenhao Lim
Joined: Oct 20, 2007
No problem. Good luck for the exam on Saturday!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com