aspose file tools*
The moose likes Threads and Synchronization and the fly likes no effect with notifyAll() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "no effect with notifyAll()" Watch "no effect with notifyAll()" New topic
Author

no effect with notifyAll()

Harry Tuttle
Greenhorn

Joined: Apr 08, 2010
Posts: 24
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Harry Tuttle
Greenhorn

Joined: Apr 08, 2010
Posts: 24
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: no effect with notifyAll()