我想知道以下是否是正确的实现
ExecutorService pool = Executors.newFixedThreadPool(MAX_NSH_THREADS);
Set<Future<Void>> futureRequest = new HashSet<Future<Void>>();
for (String host : SomeCollection)) {
Callable<Void> callable = new FileExtractor(j);
Future<Void> future = pool.submit(callable);
futureRequest.add(future);
}
for (Future<Void> future : futureRequest) {
try {
future.get();
} catch (Exception e) {
logger.error(e);
}
}
pool.shutdown();
根据Javadoc,future.get()
等待每个线程的执行完成,这(据我了解)意味着对于未来的每一个,我们将分别等待接收结果。那时的好处来自哪里,或者我做得不对?