For the sake of argument, let's say I'm implementing Future for a task which is not cancelable. The Java 6 API doc says:
After [
cancel()] returns, subsequent calls toisDone()will always returntrue.[
cancel()] returnsfalseif the task could not be cancelled, typically because it has already completed normally
It also says:
[
isDone()] returnstrueif this task completed.
But what if my cancellation fails not because the task is already completed, but because it simply cannot be cancelled? Is there a way out of this contradiction (other than making my uncancelable task cancelable and sidestepping it altogether)?
Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.- Mark PetersFuture.cancel(boolean): This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. So it seems legit to fail to cancel for whatever reason you want. - Mark Peters