}
protected Collection<Job> acquireJobs() {
Collection<Job> acquiredJobs = Collections.emptyList();
synchronized (jobExecutor) {
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
log.debug("querying for acquirable job...");
String lockOwner = getName();
JobSession jobSession = jbpmContext.getJobSession();
Job job = jobSession.getFirstAcquirableJob(lockOwner);
if (job != null) {
if (job.isExclusive()) {
ProcessInstance processInstance = job.getProcessInstance();
log.debug("loaded exclusive " + job + ", finding exclusive jobs for " + processInstance);
acquiredJobs = jobSession.findExclusiveJobs(lockOwner, processInstance);
log.debug("trying to obtain locks on " + acquiredJobs + " for " + processInstance);
}
else {
acquiredJobs = Collections.singletonList(job);
log.debug("trying to obtain lock on " + job);
}
Date lockTime = new Date();
for (Job acquiredJob : acquiredJobs) {
acquiredJob.setLockOwner(lockOwner);
acquiredJob.setLockTime(lockTime);
}
}
else {
log.debug("no acquirable jobs");
}
}
finally {
try {
jbpmContext.close();
log.debug("obtained lock on jobs: " + acquiredJobs);
}
catch (JbpmPersistenceException e) {
// if this is a stale state exception, keep it quiet
if (DbPersistenceService.isStaleStateException(e)) {