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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 3934
    
  17

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()
 
Similar Threads
blocking and waiting
Thread question in an example of Kathy and Bert Book
Code using notifyAll() runs indefinitely
blocking and waiting
notifyAll() example