aspose file tools
The moose likes Threads and Synchronization and the fly likes State of lock in case of  yield() & sleep() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "State of lock in case of  yield() & sleep()" Watch "State of lock in case of  yield() & sleep()" New topic
Author

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

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jan 30, 2000
Posts: 18670
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.


"I'm not back." - Bill Harding, Twister
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Oops. Thanks, Jim.
jply
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: State of lock in case of yield() & sleep()
 
Similar Threads
does sleep() and yield() release the lock?
Thread Class Method
difference between Yield,wait and sleep
Keeping the Lock
Thread Monitor