}
public Job execute(Environment environment) throws Exception {
DbSession dbSession = environment.get(DbSession.class);
if (dbSession==null) {
throw new JbpmException("no db-session configured");
}
JobImpl<?> job = (JobImpl<?>) dbSession.get(JobImpl.class, jobDbid);
// in case of decision jobs, the job might have been deleted
// before we execute it (they are in a list)
if (job != null) {
JobContext jobContext = new JobContext(job);
environment.setContext(jobContext);
try {
log.debug("executing job "+job+"...");
job.execute(environment);
log.debug("executed job "+job);
// if this job is locked too long, it could be unlocked by the lockmonitor and
// executed by another thread.
Date lockExpirationDate = job.getLockExpirationTime();
// can be null if it was rescheduled
if (lockExpirationDate != null) {
long lockExpiration = lockExpirationDate.getTime();
long currentTime = System.currentTimeMillis();
if (currentTime>lockExpiration) {
throw new JbpmException("job took too long: lock expired "+(currentTime-lockExpiration)+"ms ago");
}
}
} catch (Throwable exception) {
log.error("exception while executing '"+job+"'", exception);
handleJobExecutionException(environment, job, exception);