Two Laptop Bag
The moose likes Threads and Synchronization and the fly likes How can i start multiple threads ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "How can i start multiple threads ??" Watch "How can i start multiple threads ??" New topic

How can i start multiple threads ??

Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200
Hello all,

How can i start multiple threads ( number of threads to start is not defined)?
For instance
Thread t1 = new Thread("One");
Thread t2 = new Thread("Two");

In this case the main thread will wait for both t1 & t2 to exit the run method. Here i can code the way given above coz it is know that there are 2 threads. But in case the number of threads to be started is dynamic, how do i go about that?

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This kind of overlaps with your other post ... but just put them in any Collection type, eg list, map, set. Get them all started then iterate through and join.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: How can i start multiple threads ??
It's not a secret anymore!