Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help correct this calculator thread

 
Anthony Karta
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Marshal
Pie
Posts: 21202
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic