Managing Threads
Hullo.
I've been fiddling around with multi-threading but it's still very new to me. For the code below, please just assume the existence of classes LinkedCollection (which implements java.util.Collection) and Berk (which implements java.lang.Runnable), as they aren't a part of my question.
LinkedCollection<Thread> threads =new LinkedCollection<Thread>(false);
for (int i = 0; i < 10; i++)
threads.add(new Thread(new Berk(),"Thread " + i));
for (Thread t : threads)
t.start();
boolean running;
do{
running =false;
for (Thread t : threads)
if (t.isAlive()){
running =true;
break;
}
}while (running);
The first for loop creates and adds to a collection ten Threads that each perform Berk. The second for loop starts each thread in turn. The while loop iterates until it finds that none of the threads in the collection are still alive.
Is there a more concise way to do this sort of management? [I don't mean by somehow rearranging what I've just done, but rather --> ] Does Java provide some structure or pattern to monitor and manage threads with? I was looking at ThreadGroup but it doesn't seem to provide the answer...
Thanks for info and help.
Grape

