• 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

adding more threads

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I add x number of threads. For example if I want 5 threads to run, then I change my mind and want 10. Or for example I put 10 in a textbox and it will run 10 threads.

For example I usually have to do this to run 10 threads:
Thread t1 = new Thread (run);
Thread t2 = new Thread (run);
Thread t3 = new Thread (run);
Thread t4 = new Thread (run);
Thread t5 = new Thread (run);
Thread t6 = new Thread (run);
Thread t7 = new Thread (run);
Thread t8 = new Thread (run);
Thread t9 = new Thread (run);
Thread t10 = new Thread (run);

then

t1.start, t2.start, etc

Can I use a for loop somehow? Are is there and easier way of running X number of threads?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about? ...



Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic