You can use the CountDownLatch class. The idea is that you create a CountDownLatch with the number of threads you'll have, then waiting on this latch (note "await", not "wait"!):
Code:
CountDownLatch latch = new CountDownLatch(100);
// ... create threads, passing them 'latch', and start them
latch.await();
Then, each thread ends by counting down the latch:
Code:
// thread's run method
public void run() {
try {
// ... do exciting thing
} finally {
latch.countDown();
}
}
__________________
Neil Coffey
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.