This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help correct this calculator thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help correct this calculator thread" Watch "Help correct this calculator thread" New topic
Author

Help correct this calculator thread

Anthony Karta
Ranch Hand

Joined: Aug 09, 2004
Posts: 342
I feel the calculator sample in K&B book chapter 9 (thread) does not show the wait/notify scenario properly. I'm trying to modify it but got stuck now.

The idea is Calculator thread is waiting for a reader, who will send values to be powed (not implemented for now).

thanks all



SCJP 5
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

First, your calculator instance never set the reader reference, so synchronizing on the "r" variable (which is not set) just doesn't work. Second, your calculator instance is shared amoung many readers. You will have to synchronize and wait, on the correct reader to work.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
wood burning stoves
 
subject: Help correct this calculator thread
 
Similar Threads
notify and notifyAll
wait and notify
Threading discrepancies
dubt in notifyAll
wait(), notify(), notifyAll() doubt