Hi all
I'm unable to start -stop - start the
thread it gives below exception.
however first time start and stop works
What need to do?
My
java code is as below
public class ThreadTest extends Thread{
boolean runNow =true;
boolean isInterrupted = false;
int count = 0;
public void run(){
while (runNow) {
if (isInterrupted()){
runNow=false;
break;
}
System.out.println(count++);
}
}
public void stopThread(boolean graceful) {
if (graceful) {
runNow=false;
}else{
interrupt();
}
}
public static void main(
String[] args){
ThreadTest myThread = new ThreadTest();
myThread.start();
myThread.stopThread(false);
myThread.start();
}
}
Exception
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)
at ThreadTest.main(ThreadTest.java:27)