I want to wait two tasks to finish then return the result of them but sometimes I get this error. Why? Where did CancellationException come from?
public class Sh
You ask your executor service to execute your callables with a timeout of 5 seconds. According to the javadoc:
tasks that have not completed [by the end of the timeout] are cancelled
My guess is that future.get() throws a CancellationException because the timeout has been reached and the executor calls future.cancel().
You could either:
InterruptedException in your callable to handle the cancellation gracefully