public void waitForJobExecutorOnCondition( long maxMillisToWait, long intervalMillis, Callable<Boolean> condition) { JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor(); jobExecutor.start(); try { Timer timer = new Timer(); InteruptTask task = new InteruptTask(Thread.currentThread()); timer.schedule(task, maxMillisToWait); boolean conditionIsViolated = true; try { while (conditionIsViolated) { Thread.sleep(intervalMillis); conditionIsViolated = !condition.call(); } } catch (InterruptedException e) { } catch (Exception e) { throw new ActivitiException("Exception while waiting on condition: " + e.getMessage(), e); } finally { timer.cancel(); } if (conditionIsViolated) { throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded"); } } finally { jobExecutor.shutdown(); } }
protected void closeProcessEngine() { ProcessEngines.unregister(activitiProcessEngine); JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor(); if (jobExecutor != null && jobExecutor.isActive()) { jobExecutor.shutdown(); } }
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) { JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor(); jobExecutor.start(); try { Timer timer = new Timer(); InteruptTask task = new InteruptTask(Thread.currentThread()); timer.schedule(task, maxMillisToWait); boolean areJobsAvailable = true; try { while (areJobsAvailable && !task.isTimeLimitExceeded()) { Thread.sleep(intervalMillis); areJobsAvailable = areJobsAvailable(); } } catch (InterruptedException e) { } finally { timer.cancel(); } if (areJobsAvailable) { throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded"); } } finally { jobExecutor.shutdown(); } }
public void setActivateJobExecutor(boolean activateJobExecutor) { this.activateJobExecutor = activateJobExecutor; if (isActive) { log.info("Process engine configuration 'activateJobExecutor' set to " + activateJobExecutor); JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor(); if (activateJobExecutor && !jobExecutor.isActive()) { jobExecutor.start(); } else if (!activateJobExecutor && jobExecutor.isActive()) { jobExecutor.shutdown(); } } }