It's not a secret anymore!*
The moose likes Beginning Java and the fly likes about monitors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about monitors" Watch "about monitors" New topic
Author

about monitors

Awe Joey
Greenhorn

Joined: Nov 15, 2005
Posts: 4
Hi everyone, did someone programming using the wait and notify methods of the object class. this is the way the class was,
there was a clas that had 2 functions, one to store a value in a string, the other to retrieve values from thesame string.
Also wrote a class to call the retrieve method of the class above, designed it in such a way that if there is no value in the string it will wait till a value is stored
Wrote another class, to call the store method of the first class, after storing the value it calls the notify() method to reawaken the thread that is waiting.
But I noticed that the thread I was waiting for did not reawaken and instead the thread only awoke the thrid class and not the second class.
What do you think I can do to this program


Awe Joey
Anatol Bollinger
Greenhorn

Joined: Nov 10, 2005
Posts: 11
Hi.

Could you give an example? It's hard to tell without seeing the code, especially the synchonized parts.

Cheers,
Anatol
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Because this is not SCJP specific I'm moving this to Java In General (Beginner)...


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

Joined: Jul 11, 2001
Posts: 14112
notify() will just wake up one of the threads that's waiting - so if there is more than one, there is no guarantee which one. Often it's more safe to use notifyAll() instead.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Don't get me started about those stupid light bulbs.
 
subject: about monitors