Collection jobsToLock = new ArrayList();
log.debug("acquiring jobs for execution...");
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
try {
JobSession jobSession = jbpmContext.getJobSession();
log.debug("querying for acquirable job...");
Job job = jobSession.getFirstAcquirableJob(getName());
if (job!=null) {
if (job.isExclusive()) {
log.debug("exclusive acquirable job found ("+job+"). querying for other exclusive jobs to lock them all in one tx...");
List otherExclusiveJobs = jobSession.findExclusiveJobs(getName(), job.getProcessInstance());
jobsToLock.addAll(otherExclusiveJobs);
log.debug("trying to obtain a process-instance exclusive locks for '"+otherExclusiveJobs+"'");
} else {
log.debug("trying to obtain a lock for '"+job+"'");
jobsToLock.add(job);