コード例 #1
0
  /**
   * Returns true if lock succeeded, or no lock was needed. Returns false if locking was
   * unsuccessfull.
   */
  protected boolean lockJobIfNeeded() {
    try {
      if (job.isExclusive()) {
        commandExecutor.execute(new LockExclusiveJobCmd(job));
      }

    } catch (Throwable lockException) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Exception during exclusive job acquisition. Retrying job.",
            lockException.getMessage());
      }

      commandExecutor.execute(
          new Command<Void>() {
            public Void execute(CommandContext commandContext) {
              commandContext.getJobEntityManager().retryAsyncJob(job);
              return null;
            }
          });

      return false;
    }

    return true;
  }
コード例 #2
0
  protected void unlockJobIfNeeded() {
    try {
      if (job.isExclusive()) {
        commandExecutor.execute(new UnlockExclusiveJobCmd(job));
      }

    } catch (ActivitiOptimisticLockingException optimisticLockingException) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Optimistic locking exception while unlocking the job. If you have multiple async executors running against the same database, "
                + "this exception means that this thread tried to acquire an exclusive job, which already was changed by another async executor thread."
                + "This is expected behavior in a clustered environment. "
                + "You can ignore this message if you indeed have multiple job executor acquisition threads running against the same database. "
                + "Exception message: {}",
            optimisticLockingException.getMessage());
      }

    } catch (Throwable t) {
      log.error("Error while unlocking exclusive job " + job.getId(), t);
    }
  }