Using CountDownLatch
// Initialize latch with counter
final CountDownLatch latch = new CountDownLatch(5);
// Keep the latch waiting for all 5 activities to be done
try {
latch.await(); } catch (InterruptedException ignored) {
}
// Run the individual task (activity) and decrement the counter
try {
// task.run();
} finally {
latch.countDown();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.