Thursday, March 13, 2014

wait,sleep & yield

All the three functions wait, sleep and yield in java are related to threads but all of them do not belong to thread class. It is often confusing to distinguish between these three. Here is a quick difference between wait, sleep and yield functions:



WaitSleepYield
1.Method of class ObjectMethod of class ThreadMethod of class Thread
2.Non – StaticStaticStatic
3.Not invoked on a thread instanceInvoked on a thread instanceInvoked on a thread instance
4.Moves the thread to “wait’ stateMoves the thread to “wait” stateMoves the thread to “ready” state
5.Thread loose the ownership of the lockThread doesn’t loose the ownership of the lockThread doesn’t loose the ownership of the lock

No comments:

Post a Comment