Temporarily Stop a Thread in Java

Last Updated : 24 Apr, 2026

In Java, sometimes a thread needs to pause its execution for a specific period of time before continuing its work. This can be done using the Thread.sleep() method, which temporarily suspends the current thread.

  • The time is provided in milliseconds.
  • It throws an InterruptedException, so it must be handled using try-catch.

Note: suspend() method is deprecated in the latest Java version.

Syntax:

public final void suspend()

Java
class GFG extends Thread {
    public void run() {
        for (int i = 1; i < 5; i++) {
            try {
                // thread to sleep for 5 milliseconds
                Thread.sleep(5);
                System.out.println("Currently running - " 
                        + Thread.currentThread().getName());
            } catch (InterruptedException e) {
                System.out.println(e);
            }
            System.out.println(i);
        }
    }

    public static void main(String args[]) {
        // creating three threads
        GFG t1 = new GFG();
        GFG t2 = new GFG();
        GFG t3 = new GFG();

        // start threads
        t1.start();
        t2.start();
        t3.start(); // removed suspend()
    }
}

Output

Thread 2 is suspended

Explanation: Three threads (t1, t2, t3) are created and started, so they run concurrently and execute the run() method independently. Each thread prints its name and numbers 1–4 with a small delay, so the output appears interleaved and in random order due to multithreading.

Note: Thread t2 can be resumed by resume() method.

Comment