fastread homefastrread library fastread menu

Java : Start a thread twice

Tutorial by:Arena Buocel      Date: 2016-05-03 23:59:11

❰ Previous Next ❱

No. After starting a thread, it can never be started again. If you does so, an IllegalThreadStateException is thrown. In such case, thread will run once but for second time, it will throw exception.

Let's understand it by the example given below:

 
  1. public class TestThreadTwice1 extends Thread{  
  2.  public void run(){  
  3.    System.out.println("running...");  
  4.  }  
  5.  public static void main(String args[]){  
  6.   TestThreadTwice1 t1=new TestThreadTwice1();  
  7.   t1.start();  
  8.   t1.start();  
  9.  }  
  10. }  
    running
       Exception in thread "main" java.lang.IllegalThreadStateException

❰ Previous Next ❱


Java

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website