67,550
社区成员




final CountDownLatch latch = new CountDownLatch(5);
ExecutorService threadPool = Executors.newFixedThreadPool(5);
List<Future<String>> futureTaskList = new ArrayList<Future<String>>(5);
for (int i = 0; i < 5; i++) {
futureTaskList.add(threadPool.submit(new Callable<String>() {
@Override
public String call() throws Exception {
latch.countDown();
return "ok...";
}
}));
}
try {
latch.await();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
for (Future<String> future : futureTaskList) {
System.out.println(future.get());
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}