Thread Jobs in Java

Posted by Bragaadeesh on Stack Overflow See other posts from Stack Overflow or by Bragaadeesh
Published on 2010-05-19T17:48:12Z Indexed on 2010/05/19 17:50 UTC
Read the original article Hit count: 170

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading