@Override public final boolean cancel(boolean mayInterruptIfRunning) { Boolean shouldCancel = null; for (; ; ) { Object currentState = this.state; if (isDoneState(currentState)) { return false; } if (shouldCancel == null) { shouldCancel = shouldCancel(mayInterruptIfRunning); } if (!shouldCancel) { return false; } if (STATE.compareAndSet(this, currentState, CANCELLED_STATE)) { cancelled(mayInterruptIfRunning); notifyThreadsWaitingOnGet(); return true; } } }
/** * Sets the result. If {@code result} is an instance of Throwable, this * future will be completed exceptionally. That is, {@link #get} will throw * the exception rather than return it. * * @return true, if this call made this future to complete */ protected boolean setResult(Object result) { for (; ; ) { Object currentState = this.state; if (isDoneState(currentState)) { return false; } if (STATE.compareAndSet(this, currentState, result)) { done(); notifyThreadsWaitingOnGet(); runAsynchronous((ExecutionCallbackNode) currentState, result); break; } } return true; }
@Override public final boolean cancel(boolean mayInterruptIfRunning) { Boolean shouldCancel = null; for (; ; ) { Object currentState = this.state; if (isDoneState(currentState)) { return false; } if (shouldCancel == null) { shouldCancel = shouldCancel(mayInterruptIfRunning); } if (!shouldCancel) { return false; } if (STATE.compareAndSet(this, currentState, CANCELLED_STATE)) { cancelled(mayInterruptIfRunning); notifyThreadsWaitingOnGet(); return true; } } }
/** * Sets the result. If {@code result} is an instance of Throwable, this * future will be completed exceptionally. That is, {@link #get} will throw * the exception rather than return it. * * @return true, if this call made this future to complete */ protected boolean setResult(Object result) { for (; ; ) { Object currentState = this.state; if (isDoneState(currentState)) { return false; } if (STATE.compareAndSet(this, currentState, result)) { done(); notifyThreadsWaitingOnGet(); runAsynchronous((ExecutionCallbackNode) currentState, result); break; } } return true; }