This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori 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 ]