According to Javadoc, Future.get(),
throws TimeoutException and CancellationException along with 2 others.
Whats the difference between TimeoutException and CancellationException?
From what i know, CancellationException is thrown when the thread timed-out and thus the executor cancelled it. But then when is TimeoutException thrown?
is there a case that the timed-thread timed-out and not cancelled?
saw CancellationException when using ExecutorService and What is the best way to handle an ExecutionException? ampng others.
TIA.
//---------------
UPDATE
does nayone else call Future.cancel() unless the developer explicitly does?
javadoc isn't mentioning anything about CancellationException caused by it.
i've got a code coming into the system and i may have to cancel that code due to certain time-limit. but then, i gotta be able to tell when Future.cancel() returns true, it did so because the task is completed or it is cancelled.
From what it seems, Future.cancel() is returning true in both of these cases. Future.isDone()or any other of its methods are of no help.
CancellationException is thrown when the task is cancelled, by calling cancel().
TimeoutException is thrown when you ask
get()to wait for a given time for the result, and the result takes more than that time to be produced.A thread doesn't time out. And an executor doesn't cancel threads.