I have an application where by clicking buttons (that number is defined) user creates tasks (Callable) that do some calculations. I want to be able to react when the task is finished. Using Future.get() blocks the application. Is there any way to be able to react when the Callable returns the result?
private static void startTask(int i){
try{
Future<Integer> future = executor.submit(callables.get(i-1));
ongoingTasks.put(i, future);
awaitResult(future, i);
}
catch(Exception e){
e.printStackTrace();
}
}
private static void awaitResult(Future<?> future, int taskNo) throws InterruptedException, ExecutionException{
System.out.println("result : " + future.get());
JButton b = buttons.get(taskNo);
b.setEnabled(false);
}