我正在使用ExecutorService
,Future
并Callable
进行并行处理。虽然Callable
调用时可以捕获 ' 异常Future#get
,但是如何捕获所有可调用对象抛出的所有异常,然后抛出一个巨大的复合异常,例如:
ExecutorService service = Executors.newFixedThreadPool(5);
List<Future<Void>> futures = new ArrayList<Future<Void>>();
futures.add(service.submit(new TaskA());
futures.add(service.submit(new TaskB());
for (Future<Void> future : futures) {
try {
future.get();
} catch (Exception e) {
// ???
}
}
// throw the big exception here
service.shutdown();