Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about monitors

 
Awe Joey
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anatol Bollinger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because this is not SCJP specific I'm moving this to Java In General (Beginner)...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic