[concurrency-interest] Calling Future.get() after calling Future.cancel() returned false

Joe Bowbeer joe.bowbeer at gmail.com
Thu Mar 1 16:54:13 EST 2007

On 3/1/07, Peter Kovacs <peter.kovacs.1.0rc at gmail.com> wrote:
> Does it make sense to call Future.get() after calling Future.cancel()
> returned false?

Yes.  (I disagree with Jason's statement.)

If the task has already completed, then cancel returns false.

In particular, if the task has finished then a subsequent cancel()
will be ignored and a subsequent get() will return the result or
exception generated by the task.


    boolean innerCancel(boolean mayInterruptIfRunning) {
        for (;;) {
            int s = getState();
            if (ranOrCancelled(s))
                return false;
            if (compareAndSetState(s, CANCELLED))
        /* ... */
        return true;


More information about the Concurrency-interest mailing list