This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

no effect with notifyAll()

 
Harry Tuttle
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to run the example Reader / Calculator on page 753 of the scjp book. here is the code for the Reader class


and the Calculator class

When I run these classes only the waiting prompt is shown but not the total. What's wrong?

I found some explanations here
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harry Tuttle wrote:I found some explanations here


That link provides good information, but in addition to that, for some reason you put the Total report inside your catch(InterruptedException) clause. notifyAll() does not interrupt wait(), it notifies it that it should stop normally, ergo the Total report should not get called (unless some other interruption occurred). You do not want the report in the catch clause, you want it either just after the wait() (at the end of the try clause) or just after the catch clause.
 
Harry Tuttle
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
Harry Tuttle wrote:I found some explanations here


That link provides good information, but in addition to that, for some reason you put the Total report inside your catch(InterruptedException) clause. notifyAll() does not interrupt wait(), it notifies it that it should stop normally, ergo the Total report should not get called (unless some other interruption occurred). You do not want the report in the catch clause, you want it either just after the wait() (at the end of the try clause) or just after the catch clause.


Thank you. In this case I must say, you can learn from errors!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic