cmh0114 0 Newbie Poster

I'm trying to create a game with Java, and it includes a timer, which I did with an extension of Thread. The timer is put in a loop. Effectively:

public class Game
do{

System.out.println("Start");
playGameThread.start();
timerThread.start();

timerThread.join();
playGameThread.allDone = true;
playGameThread.join();

System.out.println("Finish");
}while(play_again == 'Y');    
}

public class playGameThread extends Thread{
while(allDone == false){
...
}
}

That's the gist of it -- it prints "Begin," the game starts, the timer starts, and when the timer finishes, a variable within the game thread is set to end, and the program waits for the thread to end, and then it prints "Finish". But on the second iteration of the loop, the lines for starting the threads throws an IllegalThreadStateException, and when I place it in a try-catch, it prints "Begin" then "Finish" without executing the threads. I don't want to resume the threads from where they left off, I want to completely restart them from the top. Any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.