1.

Can you start a thread twice?

Answer»

No, it's not at all possible to restart a thread once a thread gets started and completes its execution. Thread only runs once and if you try to run it for a SECOND time, then it will throw a runtime exception i.e., java.lang.IllegalThreadStateException. 

EXAMPLE

public CLASS TestThreadTwice1 extends Thread{ public VOID run(){ System.out.println(" thread is executing now........"); } public static void main(String args[]){ TestThreadTwice1 t1=new TestThreadTwice1(); t1.start(); t1.start(); } }

Output:

thread is executing now........ Exception in thread "main" java.lang.IllegalThreadStateException


Discussion

No Comment Found