Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why notifyAll do nothing

 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone:
I use wait/notify to implement lock/unlock function. but the thread waitting to lock record is not notified. Why?
Thanks.
 
dennis hu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul:
You must confirm waint and notifyAll in a same object,otherwise it will failure.
~dennis ~
 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does mean "same object". I think thread A want to lock a record, but thread B lock it at that time, so A will wait until B unlock it and
notify A. Am I right?
 
dennis hu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul:
You are rignt!
If thread A want to lock a record that tread B had locked,thread A must wait until thread B unlock the record and notify it.
But what I mean "same objcet" is thread A and B must have the same reference of the object who contained wait() and notifyAll() but not means record.
~dennis~
 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dennis:
Thanks. I put wait/notify method into LockManager, a object take charge of locking record, it can work so well.
Thank you.
Paul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic