public class CollectionInitUtils {
public static <T> T[] ar(final T... ts) {
return ts;
}
public static <T> Set<T> set(final T... ts) {
return new HashSet<T>(Arrays.asList(ts));
}
public static <K, V> Map<K, V> zipMap(final K[] keys, final V[] values) {
final Map<K, V> res = new HashMap<K, V>();
for (int i = 0; i < keys.length; i++) {
res.put(keys[i], values[i]);
}
return res;
}
}
ExecutorService executorService = Executors.newFixedThreadPool(5);
int tasksCount = 10;
final CountDownLatch latch = new CountDownLatch(tasksCount);
for (int i = 0; i < tasksCount; i++ ) {
executorService.execute(new Runnable() {
public void run() {
try {
// Do some work;
} finally {
latch.countDown();
}
}
});
}
try {
latch.await();
} catch (InterruptedException e) {
// todo >> handle exception
}
// All done!
// Do some more work
}