@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; } } }
@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; } } }