A
angelochen960
Hi,
I have a code similar to the following, it has a outer loop, for every
iteration it starts 2 threads to execute some code at background, then
proceed to the next iteration, I'd like the code to wait at end of
every iteration until all the threads have ended, any idea how to
achieve this? Thanks.
Angelo
List<String> lst = new ArrayList();
for (final String j : lst) {
for (int i = 0; i < 2; i++) {
new Thread(new Runnable() {
public void run() {
// do something with string j
}
}).start();
}
// proceed to next iteration when all the thraeds have done
}
I have a code similar to the following, it has a outer loop, for every
iteration it starts 2 threads to execute some code at background, then
proceed to the next iteration, I'd like the code to wait at end of
every iteration until all the threads have ended, any idea how to
achieve this? Thanks.
Angelo
List<String> lst = new ArrayList();
for (final String j : lst) {
for (int i = 0; i < 2; i++) {
new Thread(new Runnable() {
public void run() {
// do something with string j
}
}).start();
}
// proceed to next iteration when all the thraeds have done
}