This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i start multiple threads ??

 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
t1.start();
t2.start();
t1.join();
t2.join();

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?

Regards,
Saj
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic