Can we start a thread twice?
No. After staring a thread, it can never be started again. If you does so, an IllegalThreadStateException is thrown. For Example:
public class TestThreadTwice1 extends Thread{
public void run(){
System.out.println("running...");
}
public static void main(String args[]){
TestThreadTwice1 t1=new TestThreadTwice1();
t1.start();
t1.start();
}
}
Output:runningException in thread "main" java.lang.IllegalThreadStateException
No comments:
Post a Comment