This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why notifyAll do nothing

 
Paul Sun
Greenhorn
Posts: 19
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic