Tutoriallearn.com

Easy Learning


Home

Search Tutoriallearn.com :



resume() method of thread

  • The resume() method of thread class is used with suspend() method.
  • It is used to resume a thread which was suspended using suspend() method.

Syntax

public final void resume()

Example

 public class  ThreadExample  extends Thread {
    
    public void  run() {
        for(int i=0;i<5;i++){
            System.out.println("Thread name: " + Thread.currentThread().getName());
        }
    }
  public static void  main(String args[]) {
      ThreadExample t1 = new ThreadExample();
      ThreadExample t2 = new ThreadExample();
      
      t1.start();
      t2.start();
      
      t2.suspend();
      t2.resume();
  }    
}

Output

Output will be vary after every execution

Thread name: Thread-0
Thread name: Thread-1
Thread name: Thread-1
Thread name: Thread-1
Thread name: Thread-1
Thread name: Thread-0
Thread name: Thread-1
Thread name: Thread-0
Thread name: Thread-0
Thread name: Thread-0





© Copyright 2016-2025 by tutoriallearn.com. All Rights Reserved.