Win a copy of High Performance Python for Data Analytics this week in the Python forum!

Mark Jackson

Greenhorn
+ Follow
since Jan 11, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mark Jackson

Davin,
Nice score! Which mocks did you take?
18 years ago
Kathy,
Thanks very much for the learning opportunity
Yes, I made it through the last chapter of the SCJP material, but I'm actually working *backwards* through your book (chapter by chapter). I had started with the Heller / Roberts book.
After reading on javaranch that the thread questions are some of the more difficult exam questions, I jumped right to chapter 9 in your book.
I plan to schedule my exam once I see how I'm doing on the mock exams (current results are confidential ).
Thanks for your well-written study guide!
Regards,
Mark.
Hello --
When running the Calculator Thread example from the Kathy Sierra 1.4 book (see below, p. 533), it hangs with the following output when the calculator thread is started first [1].
Output:

I believe the reason is that the calculator thread starts first and grabs its object lock first. This allows the notifyAll() call to occur *before* any of the other threads are waiting. Therefore, notifyAll() does nothing.
If I modify the code to start the calculator thread *after* the Reader threads, the code appears to work correctly and generates the following output:

Q. Is the example really incorrect?