return true if the task is successfully cancelled.
@return
325190
public synchronized boolean cancel() {
    if (this.taskFuture != null && this.taskFuture.cancel(true)) {
      this.taskStateTracker.onTaskRunCompletion(this);
      this.completeShutdown();
      return true;
    } else {
      return false;
    }
  }
1040417
@Override
    public boolean isCancelled() {

        //F743-609CodRev - read volatile variable only once
        boolean cancelled = ivCancelled;

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "isCancelled: " + cancelled + " Future object: " + this);
        }

        return (cancelled);
    }
1225249
public synchronized int clear() {
    final int count = taskQueue.size();
    for (final TaskEntity task : taskQueue) {
      canceledTasks.add(task);
    }
    taskQueue.clear();
    return count;
  }
69718
public boolean isFinished()
	{
		if (finished)
			return true;

		try
		{
			final int code = exitCode();

			finished(code);

			return true;
		}
		catch (IllegalThreadStateException e)
		{
			return false;
		}
	}
418440
def task_done(self, task_id, result):
        """"""
        try:
            task = self.tasks.pop(task_id)
        except KeyError:
            return  # result of previously timeout Task
        else:
            if task.future.cancelled():
                task.set_running_or_notify_cancel()
            elif isinstance(result, BaseException):
                task.future.set_exception(result)
            else:
                task.future.set_result(result)

            self.task_done_callback()
418439
public boolean stop() {
        if (scheduledFuture != null && !scheduledFuture.isCancelled()) {
            scheduledFuture.cancel(DO_NOT_INTERRUPT_IF_RUNNING);
            if (LOG.isDebugEnabled()) {
                LOG.debug("{} Cache Manager stopped.", cache.getClass().getSimpleName());
            }
            return true;
        }
        return false;
    }
55518
protected final boolean hasScheduledTasks() {
        Queue<ScheduledFutureTask<?>> scheduledTaskQueue = this.scheduledTaskQueue;
        ScheduledFutureTask<?> scheduledTask = scheduledTaskQueue == null ? null : scheduledTaskQueue.peek();
        return scheduledTask != null && scheduledTask.deadlineNanos() <= nanoTime();
    }
229744
public boolean isFailure(R result, Throwable failure) {
    for (BiPredicate<R, Throwable> predicate : failureConditions) {
      try {
        if (predicate.test(result, failure))
          return true;
      } catch (Exception ignored) {
        // Ignore confused user-supplied predicates.
        // They should not be allowed to halt execution of the operation.
      }
    }

    // Fail by default if a failure is not checked by a condition
    return failure != null && !failuresChecked;
  }
35833
private boolean blocked(Task task) throws InterruptedException
   {
      lock.lockInterruptibly();

      try
      {
         TaskAttribute executing =
               enabled.size() > 0
                     ? enabled.get(enabled.size() - 1).getCommand().getTaskAttribute()
                     : null;
         {
            switch (task.getCommand().getTaskAttribute())
            {
               case SIMPLE :
                  if (executing == null || executing == TaskAttribute.SIMPLE)
                     return false;
                  else
                     return true;
               case HEAD_OF_QUEUE :
                  return false;
               case ORDERED :
                  if (executing == null)
                     return false;
                  else
                     return true;
               default :
                  throw new RuntimeException("Unsupported task tag: "
                        + task.getCommand().getTaskAttribute().name());
            }
         }
      }
      finally
      {
         lock.unlock();
      }
   }
1217970
protected boolean waitForTasks() {
		synchronized (this.tasks) {
			while (!this.closed && !this.hasTaskPending()) {
				try {
					this.tasks.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}

		return !this.closed;
	}
1176262
final boolean abort() {
        if (!taken.get()) {
            // aborting always runs before connection
            // happens. If we reach this point the request
            // can be active or suspended
            // but nor delivered or committed
            result = BaasResult.cancel();
            // we can simply forcefully set the value
            // to ABORTED to let the resource been cleaned up
            suspendableHandler.set(Signal.ABORTED);
            finish();
            return true;
        }
        return false;
    }
896559
protected boolean wasStopIssuedOnJob() {
        StopLock stopLock = getStopLock(); // Store in local variable to facilitate Ctrl+Shift+G search in Eclipse
        synchronized (stopLock) {
            if (runtimeWorkUnitExecution.getBatchStatus().equals(BatchStatus.STOPPING)) {
                return true;
            } else {
                return false;
            }
        }
    }
1359973
private boolean processCancelRequests() {
        // Try to make this as fast as possible. Don't need to sync
        // since if a cancel gets added after checking the size, we will
        // see it next time.
        if (cancelList.size() == 0) {
            return false;
        }

        boolean needSelectToOccur = false;

        final boolean bTrace = TraceComponent.isAnyTracingEnabled();
        synchronized (cancelList) {
            for (CancelRequest req : this.cancelList) {
                if (req.state == CancelRequest.Ready_To_Cancel) {
                    if (bTrace && tc.isDebugEnabled()) {
                        Tr.debug(this, tc, "cancelling key " + req.key);
                    }
                    req.key.cancel();
                    req.state = CancelRequest.Ready_To_Signal_Done;
                    needSelectToOccur = true;
                }
            }
        } // end-sync
        return needSelectToOccur;
    }
195990
private void checkCancelRequestedFlag() {

		if (this.cancelRequested.compareAndSet(true, false)) {
			final TaskCancelResult tsr = cancelTask();
			if (tsr.getReturnCode() != AbstractTaskResult.ReturnCode.SUCCESS
				&& tsr.getReturnCode() != AbstractTaskResult.ReturnCode.TASK_NOT_FOUND) {
				LOG.error("Unable to cancel vertex " + this + ": " + tsr.getReturnCode().toString()
					+ ((tsr.getDescription() != null) ? (" (" + tsr.getDescription() + ")") : ""));
			}
		}
	}
1210184
@Private
  @Override
  public void cancelled(final int pTaskletId) {
    assert taskletId == pTaskletId;

    this.cancelled.set(true);
    if (callbackHandler != null) {
      executor.execute(new Runnable() {
        @Override
        public void run() {
          callbackHandler.onFailure(new InterruptedException("VortexFuture has been cancelled on request."));
        }
      });
    }
    this.countDownLatch.countDown();
  }
401598
private boolean validateProcessInstance(ProcessInstance processInst) {
        Integer status = processInst.getStatusCode();
        if (WorkStatus.STATUS_CANCELLED.equals(status)) {
            logger.info("ProcessInstance has been cancelled. ProcessInstanceId = " + processInst.getId());
            return false;
        } else if (WorkStatus.STATUS_COMPLETED.equals(status)) {
            logger.info("ProcessInstance has been completed. ProcessInstanceId = " + processInst.getId());
            return false;
        } else return true;
    }
52257
final void rescheduleIfNeeded() {
		if (executeEvery > 0 && !TaskScheduler.stopping) {
			synchronized (this) {
				status = Task.STATUS_NOT_STARTED;
				executeIn(executeEvery);
			}
			TaskScheduler.schedule(this);
		} else if (nextExecution > 0 && !TaskScheduler.stopping) {
			synchronized (this) {
				this.status = Task.STATUS_NOT_STARTED;
			}
			TaskScheduler.schedule(this);
		}
	}