The following modification has the main thread join each sub thread which will cause the main thread to wait for each sub thread to complete.
Joined: Jul 27, 2001
Rovas, calling Thread.start() on one line and Thread.join() on the same thread a line later is not the most useful of patterns. It's like running the code without starting a thread, only there's a lot more overhead. I'm having trouble imagining circumstances when you'd ever want to join() immediately after start()ing. I guess it would keep the code from mucking with your ThreadLocals or throwing unexpected Errors/RuntimeExceptions at you.
I've added a word to my response above to clarify.
Joined: Aug 08, 2003
Thanks for pointing that out, David. The code that I submitted is not multi-threaded at all. As stated in the first reply(I'd use the user name if i could see - come on javaranch), I should put each sub-thread in a collection and then call join on each thread.
Joined: Jan 07, 2003
I should put each sub-thread in a collection and then call join on each thread.
I was wondering how to code it, if you can help me with it; that would be very useful. Thank you in advance Garandi