/// <summary> /// /// </summary> public virtual void Run() { log.LogInformation("starting to acquire async jobs due"); Thread.CurrentThread.Name = "activiti-acquire-timer-jobs"; ICommandExecutor commandExecutor = asyncExecutor.ProcessEngineConfiguration.CommandExecutor; while (!isInterrupted) { try { AcquiredTimerJobEntities acquiredJobs = commandExecutor.Execute(new AcquireTimerJobsCmd(asyncExecutor)); if (!(acquiredJobs is null)) { commandExecutor.Execute(new CommandAnonymousInnerClass(this, acquiredJobs)); // if all jobs were executed millisToWait = asyncExecutor.DefaultTimerJobAcquireWaitTimeInMillis; int jobsAcquired = acquiredJobs.Size(); if (jobsAcquired >= asyncExecutor.MaxTimerJobsPerAcquisition) { millisToWait = 0; } } } catch (ActivitiOptimisticLockingException optimisticLockingException) { if (log.IsEnabled(LogLevel.Debug)) { log.LogDebug($@"Optimistic locking exception during timer job acquisition. If you have multiple timer executors running against the same database, this exception means that this thread tried to acquire a timer job, which already was acquired by another timer executor acquisition thread. This is expected behavior in a clustered environment. You can ignore this message if you indeed have multiple timer executor acquisition threads running against the same database. Exception message: {optimisticLockingException.Message}"); } } catch (ObjectDisposedException ex) { if (log.IsEnabled(LogLevel.Debug)) { log.LogDebug($@"Optimistic locking exception during timer job acquisition. If you have multiple timer executors running against the same database, this exception means that this thread tried to acquire a timer job, which already was acquired by another timer executor acquisition thread. This is expected behavior in a clustered environment. You can ignore this message if you indeed have multiple timer executor acquisition threads running against the same database. Exception message: {ex.Message}"); } } catch (Exception e) { log.LogError($"exception during timer job acquisition: {e.Message}"); millisToWait = asyncExecutor.DefaultTimerJobAcquireWaitTimeInMillis; } if (millisToWait > 0) { try { if (log.IsEnabled(LogLevel.Debug)) { log.LogDebug($"timer job acquisition thread sleeping for {millisToWait} millis"); } lock (MONITOR) { if (!isInterrupted) { isWaiting = true; Monitor.Wait(MONITOR, TimeSpan.FromMilliseconds(millisToWait)); } } if (log.IsEnabled(LogLevel.Debug)) { log.LogDebug("timer job acquisition thread woke up"); } } catch (Exception e) { if (log.IsEnabled(LogLevel.Debug)) { log.LogDebug("timer job acquisition wait interrupted"); } } finally { isWaiting = false; } } } log.LogInformation("stopped async job due acquisition"); }
public CommandAnonymousInnerClass(AcquireTimerJobsRunnable outerInstance, AcquiredTimerJobEntities acquiredJobs) { this.outerInstance = outerInstance; this.acquiredJobs = acquiredJobs; }