}
// create an executor
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(10));
try {
// run them all
List<Future<Object>> futures = executor.invokeAll(tasks);
// and wait for them all to be done
for(Future<Object> f : futures){
f.get();
}
executor.shutdown();