Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

State of lock in case of yield() & sleep()  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello javaranch.Please correct me regarding yield & sleep methods( in case of locks)-
sleep method does not release the lock on an object where as yield does.
Is the above stmt correct or i have got it wrong.
Thanks for the correction in advance
kshyam
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither <code>sleep</code> nor <code>yield</code> releases any locks held by the thread. Once a thread has an object's lock, it only releases it by calling one of the object's <code>wait</code> methods or by exiting <code>run</code>.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first sentence is entirely correct; the second needs a small correction: Once a thread has an object's lock, it only releases it by calling one of the object's wait() methods, or by exiting whichever synchronized block or method acquired the lock in the first place.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. Thanks, Jim.
jply
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!