| Slno |
|
Wait |
Sleep |
| 1- |
Locking |
The wait() method releases the lock on an object and gives others chance to execute. |
The sleep() method does not release the lock of an object for a specified time or until interrupted. |
| 2- |
Context |
The wait() method can only be called from Synchronized context i.e. using a synchronized block or synchronized method. |
The sleep() method can be called from any context. |
| 3- |
Class belongs |
The wait() method belongs to java.lang.Object class thus can be called on any Object. |
The sleep() method belongs to java.lang.Thread class, thus can be called on Threads. |
| 4- |
Wake up condition |
A waiting thread can be awake by notify() or notifyAll() method. |
A sleeping can be awakened by interrupt or time expires. |