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:
|1.||Method of class Object||Method of class Thread||Method of class Thread|
|2.||Non – Static||Static||Static|
|3.||Not invoked on a thread instance||Invoked on a thread instance||Invoked on a thread instance|
|4.||Moves the thread to “wait’ state||Moves the thread to “wait” state||Moves the thread to “ready” state|
|5.||Thread loose the ownership of the lock||Thread doesn’t loose the ownership of the lock||Thread doesn’t loose the ownership of the lock|
Thus one thing that is common to all the three functions is that they change the state of thread.
Please let us know for any queries or feedback in the comments sections below.