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
Joined: Nov 22, 2008
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>.
Joined: Jan 30, 2000
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.