• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can i start multiple threads ??

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic