Thread Jobs in Java
- by Bragaadeesh
Hi,
I want to spawn 200 threads simultaneously in Java. What I'm doing right now is running into a loop and creating 200 threads and starting them. After these 200 gets completed, I want to spawn another 200 set of threads and so on.
The gist here is that the first 200 threads I spawned need to be FINISHED before spawning the next set. I tried the code below, but its not working
for(int i=0;i<200;i++){
Thread myThread = new Thread(runnableInstance);
myThread.start();
}
for(int i=0;i<200;i++){
Thread myThread = new Thread(runnableInstance);
myThread.start();
}
Note: I have intentionally put the for loop Twice, but the desired effect I intend is not happening simply because the second for loop is executed before the first set of threads end their execution.
Please advise