I'm performing a computation using java Callable and ExecutorService:
ExecutorService threadExecutor = Executors.newCachedThreadPool();
for (TaskCallable task: tasks) {
threadExecutor.submit(task);
}
I want to let the tasks run for at most 2 minutes. but If I call :
task.get(2, TimeUnit.MINUTES);
then it will block immediately! and not let me assign a timeout for the other tasks, until the timeout ends.
I can use
threadExecutor.invokeAll(tasks, 2, TimeUnit.MINUTES);
but it returns List of Futures, and I can't know what task belongs to which Future.