In Java, wait() and sleep() are commonly used methods that pause the execution of a thread. Although both seem similar, they differ significantly in behavior, usage, and purpose, especially in multithreaded environments.
sleep() Method
The sleep() method is a static method of the Thread class. It temporarily pauses the execution of the currently executing thread for a specified period of time.
- Causes the thread to pause for a fixed time
- Does not release the lock held by the thread
- Can be used outside synchronized blocks
- Throws InterruptedException
Syntax
public static void sleep(long millis) throws InterruptedException
Example:
class GFG {
public static void main(String[] args) {
try {
System.out.println("Thread going to sleep");
Thread.sleep(2000);
System.out.println("Thread woke up");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Output:
Thread going to sleep
Thread woke up
Explanation: The current thread pauses execution for 2 seconds and then resumes automatically after the specified time.
wait() Method
The wait() method is a non-static method of the Object class. It causes the current thread to wait until another thread invokes notify() or notifyAll() on the same object.
- Belongs to java.lang.Object
- Must be called inside a synchronized block
- Releases the lock held on the object
- Thread resumes only after notification
- Throws InterruptedException
Syntax
public final void wait() throws InterruptedException
Example:
class GFG {
public static void main(String[] args) {
final Object lock = new Object();
Thread t1 = new Thread(() -> {
synchronized (lock) {
try {
System.out.println("Thread waiting");
lock.wait();
System.out.println("Thread resumed");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Thread t2 = new Thread(() -> {
synchronized (lock) {
System.out.println("Thread notifying");
lock.notify();
}
});
t1.start();
t2.start();
}
}
Output
Thread waiting Thread notifying Thread resumed
Explanation: The first thread waits until the second thread calls notify() on the same object. During waiting, the lock is released and later reacquired.

The diagram illustrates how a thread moves between different states when wait() and sleep() methods are used.
wait() vs sleep()
| Wait() | Sleep() |
|---|---|
| Wait() method belongs to Object class. | Sleep() method belongs to Thread class. |
| Wait() method releases lock during Synchronization. | Sleep() method does not release the lock on object during Synchronization. |
| Wait() should be called only from Synchronized context. | There is no need to call sleep() from Synchronized context. |
| Wait() is not a static method. | Sleep() is a static method. |
Wait() Has Three Overloaded Methods:
| Sleep() Has Two Overloaded Methods:
|
| public final void wait(long timeout) | public static void sleep(long millis) throws Interrupted_Execption |