Sunday, October 19, 2025
HomeLanguagesJavaJava Program to Run Multiple Threads

Java Program to Run Multiple Threads

Thread is a lightweight process. A process in execution is called a program. A subpart of a program is called a thread. Threads allow a program to operate more efficiently by doing multiple things at the same time performing complicated tasks in the background without interrupting the main program execution.

All threads can communicate with each other. Java provides a Thread class to achieve thread programming.  Thread class provides constructors and methods to create and perform operations on a thread. 

Various Thread Methods:

  • start(): method is used to start the execution of the thread.
  • run(): method is used to do an action.
  • sleep(): This method sleeps a thread for the specified amount of time.
  • resume(): This method is used to resume the suspended thread.
  • stop(): This method is used to stop the thread.
  • destroy(): This method is used to destroy the thread group and all of its subgroups.

Syntax:

public class Thread
   extends Object
   implements Runnable

Java




// Java Program to Run Multiple Threads
  
// class extends thread class
class Main extends Thread {
  
    // run method implementation
    public void run()
    {
        System.out.println("Geeks for Geeks");
    }
  
    // in the main method
    public static void main(String args[])
    {
        // object creation
        Main t1 = new Main();
  
        // object creation
        Main t2 = new Main();
  
        // object creation
        Main t3 = new Main();
  
        // start the thread
        t1.start();
  
        // start the thread
        t2.start();
  
        // start the thread
        t3.start();
    }
}


Output

Geeks for Geeks
Geeks for Geeks
Geeks for Geeks
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS