final CountDownLatch countDownLatch = new CountDownLatch(size);
final ListeningExecutorService executorsService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(size));
final List<Exception> createExceptions = new ArrayList<>();
for(int i=0;i<size;i++){
executorsService.submit(new Runnable() {
@Override
public void run() {
try {
//dosomething
} catch (Exception e) {
//dosomething
} finally {
countDownLatch.countDown();
}
}
});
}
try {
countDownLatch.await();
if(!executorsService.isShutdown()){
executorsService.shutdown();
}
} catch (InterruptedException e) {
//dosomething
}