throw new AssertionFailedError("Expected finished process instance '"+processInstanceId+"' but it was still in the db");
}
}
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
JobExecutor jobExecutor = null;
AsyncExecutor asyncExecutor = null;
if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
} else {
asyncExecutor = processEngineConfiguration.getAsyncExecutor();
asyncExecutor.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);
try {
areJobsAvailable = areJobsAvailable();
} catch(Throwable t) {
// Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
// isolation level doesn't allow READ of the table
}
}
} catch (InterruptedException e) {
// ignore
} finally {
timer.cancel();
}
if (areJobsAvailable) {
throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
jobExecutor.shutdown();
} else {
asyncExecutor.shutdown();
}
}
}