I have a scenario where I have to execute 5 thread asynchronously for the same callable. As far as I understand, there are two options:
1) using submit(Callable)
ExecutorService executorService = Executors.newFixedThreadPool(5);
List<Future<String>> futures = new ArrayList<>();
for(Callable callableItem: myCallableList){
futures.add(executorService.submit(callableItem));
}
2) using invokeAll(Collections of Callable)
ExecutorService executorService = Executors.newFixedThreadPool(5);
List<Future<String>> futures = executorService.invokeAll(myCallableList));
- What should be the preferred way?
- Is there any disadvantage or performance impact in any of them compared to the other one?