Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

adding more threads  RSS feed

 
Steven Alvarez
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about? ...



Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!