«Back to Home

Core Java

Topics

Start A Thread Twice

Can we start a thread twice?

No, we cannot start a thread twice. After starting a thread, it can never be started again. If we do then an IllegalThreadStateException is thrown. In this case, the thread will run once but next time, it will throw an exception.
 
Let’s see an example, given below.
 
Code
  1. public class Car extends Thread {  
  2.     public void run() {  
  3.         System.out.println("Car is running...");  
  4.     }  
  5.     public static void main(String args[]) {  
  6.         Car t1 = new Car();  
  7.         t1.start();  
  8.         t1.start();  
  9.     }  
  10. }  
9

Output

10

In the example, mentioned above, we observed that the first call to start() resulted in an execution of run() method. On the other hand, the exception is thrown, when we tried to call the start() next time.
 
Summary

Thus, we learnt, we cannot start a thread twice. After starting a thread, it can never be started again in Java multithreading.