code: @Override
      public boolean cancel(long taskId) throws Exception {
          StringBuilder update = new StringBuilder(87).append("UPDATE Task t SET t.STATES=")
                          .append(TaskState.CANCELED.bit + TaskState.ENDED.bit)
                          .append(",t.VERSION=t.VERSION+1 WHERE t.ID=:i AND t.STATES<")
                          .append(TaskState.ENDED.bit);
  
          final boolean trace = TraceComponent.isAnyTracingEnabled();
          if (trace && tc.isEntryEnabled())
              Tr.entry(this, tc, "cancel", taskId, update);
  
          EntityManager em = getPersistenceServiceUnit().createEntityManager();
          try {
              Query query = em.createQuery(update.toString());
              query.setParameter("i", taskId);
              boolean canceled = query.executeUpdate() > 0;
  
              if (trace && tc.isEntryEnabled())
                  Tr.exit(this, tc, "cancel", canceled);
              return canceled;
          } finally {
              em.close();
          }
      }
docs: Update the record for a task in the persistent store to indicate that the task is canceled.
  
  @param taskId unique identifier for a persistent task
  @return true if the state of the task was updated as a result of this method, otherwise false.
  @throws Exception if an error occurs when attempting to update the persistent task store.