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
posted
0
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
posted
0
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.