I am in need of help with a Java class project. The program is not difficult at all but our book doesn't cover the subject matter at hand very well at all. I've been researching a lot and have a better book on the way from Amazon. Now... I know the program has the potential to work as it sort of does, just not exactly the way it needs to.
The output that I get is that my countdown "timer" is repeated 5 times.
This means that it goes 5,4,3,2,1 BLAST OFF! exactly five times... it needs to happen once. Everything seems to happen out of sequence.
With each repitition I get one of my threads printed and displayed.
It needs to do the countdown 1 time and then display my 5 thread names and start them. That's all this program has to do.
Any help would be greatly appreciated! I'm very new to programming.
package threadcount;
public class ThreadCount implements Runnable {
private int ignitionTimer = 5;
private static int threadCount = 0;
private int numThreads = ++threadCount;
public void run() {
while(true) {
System.out.println("Countdown = " + ignitionTimer);
if (--ignitionTimer == 0) {
System.out.println("\nBlast Off!");
return;
}
}
}
public static void main(String[] args)
throws java.lang.InterruptedException {
for (int i = 0; i < 5; i++) {
Runnable tv = new ThreadCount();
Thread.sleep(1000);
Thread thrd = new Thread(tv);
thrd.start();
System.out.println(thrd.getName()+" is starting...");
}
System.out.println("\nThreads have now been started\n");
}
}

New Topic/Question
Reply



MultiQuote








|