How to Temporarily Suspend a Thread in Java?

Threads are an important aspect of Java programs. They are also known as lightweight processes. Every program in Java has at least a main thread. They play a very important role to run multiple tasks at the same time. They run in the background and do not affect the execution of the main program. The use of multiple threads simultaneously is called multithreading.

States of a Thread

A thread can exist in either of the following states. It has a complete lifecycle from its creation to destruction. The thread lifecycle states are-

  • New- It is the first stage when the thread is created. It is not yet executed.

  • Runnable- It is the state when is thread is running or is ready to run.

  • Blocked/waiting- It is the state when the thread is waiting for resources and is inactive.

  • Suspended- It is the state when the thread is temporarily inactive.

  • Terminated- It is the state when the thread has stopped its execution.

Temporarily Suspend a Thread in Java

A thread has to be in the suspended state if we want to suspend it. In this state, the thread is temporarily suspended, i.e., it is inactive. The suspend() method is used to suspend the thread temporarily. It will get suspended until resumed in the program. We can resume the suspended thread by the resume() method.


public final void suspend()

The suspend() method is a final method that means it cannot be overridden by the subclasses. Also, as the return data type is void, it does not return any value to the user. The method is public.

The suspend() method stops the thread temporarily until the resume() method is called on it.


Following is an example to use the suspend() method to temporarily suspend a thread in Java.

public class Main extends Thread {
   public void run()
      try {
      //print the current thread
         System.out.println("Current thread is thread number " + Thread.currentThread().getName());
      catch (Exception e) {

   public static void main(String[] args) throws Exception

      //1 thread created
      Main t1=new Main();

      //running the threads

      //putting it to sleep for 3ms

      //now suspend the thread 
      System.out.println("Thread is suspended");

      //resume the thread
      System.out.println("Thread is Resumed");


Following is the output of the above code

Current thread is thread number Thread-0
Thread is suspended
Thread is Resumed


In the above code, we have created a thread. We run that thread and then put it to sleep for 3 milliseconds. Then to temporarily suspend a thread, we have used the suspend() method. It temporarily stops the execution of that thread. Later, the thread is resumed by the resume() method.

Hence, we can conclude that the suspend() method can be used to temporarily suspend a thread in Java. Although this method is deprecated, it is advisable to know the consequences of deadlock and use this.

Updated on: 24-Jul-2023


Kickstart Your Career

Get certified by completing the course

Get Started