File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Why does it get stuck? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Why does it get stuck?" Watch "Why does it get stuck?" New topic
Author

Why does it get stuck?

Yongping Wang
Ranch Hand

Joined: May 15, 2001
Posts: 40
I just couldn't figure out why it gets stuck when running the following code:

Thanks for any comments.
Y.Wang
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What happens if the Calculator thread finishes before the readers get started? The notifyAll() notifies nothing, it is not queued. The readers will then wait for ever.
I think the authors of the book where this comes from have made a correction in the book's errata.

[ April 18, 2003: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
So, which book are we talking about here?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
 
subject: Why does it get stuck?
 
Threads others viewed
Thread question in an example of Kathy and Bert Book
Code using notifyAll() runs indefinitely
synchronization doubt
blocking and waiting
blocking and waiting
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture