Two Laptop Bag
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help correct this calculator thread" Watch "Help correct this calculator thread" New topic

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

Henry Wong

Joined: Sep 28, 2004
Posts: 20531

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Help correct this calculator thread
It's not a secret anymore!