code: public synchronized int cancelTask(final int taskId) throws UnsuccessfulException, NotFoundException {
      if (getTask(taskId, runningTasks) != null) {
        throw new UnsuccessfulException("The task " + taskId + " is running");
      } else if (getTask(taskId, finishedTasks) != null) {
        throw new UnsuccessfulException("The task " + taskId + " has finished");
      }
  
      final TaskEntity task = getTask(taskId, taskQueue);
      if (task == null) {
        final String message =
            new StringBuilder().append("Task with ID ").append(taskId).append(" is not found").toString();
        throw new NotFoundException(message);
      } else {
        taskQueue.remove(task);
        canceledTasks.add(task);
        return taskId;
      }
    }
docs: Update the record of task to mark it as canceled.