code: public synchronized void cancelTask(long jobId, int taskId) {
      Pair<Long, Integer> id = new Pair<>(jobId, taskId);
      TaskInfo.Builder taskInfo = mUnfinishedTasks.get(id);
      if (!mTaskFutures.containsKey(id) || taskInfo.getStatus().equals(Status.CANCELED)) {
        // job has finished, or failed, or canceled
        return;
      }
  
      Future<?> future = mTaskFutures.get(id);
      if (!future.cancel(true)) {
        taskInfo.setStatus(Status.FAILED);
        taskInfo.setErrorMessage("Failed to cancel the task");
        finishTask(id);
      }
    }
docs: Cancels the given task.
  
  @param jobId the job id
  @param taskId the task id