public class JTAJobRunShell extends JobRunShell
{
public JTAJobRunShell(Scheduler scheduler, TriggerFiredBundle bndle)
{
super(scheduler, bndle);
transactionTimeout = null;
}
}
public class JobRunShell extends SchedulerListenerSupport
implements Runnable
{
public JobRunShell(Scheduler scheduler, TriggerFiredBundle bndle)
{
jec = null;
qs = null;
firedTriggerBundle = null;
this.scheduler = null;
shutdownRequested = false;
this.scheduler = scheduler;
firedTriggerBundle = bndle;
}
public void run()
{
//添加到内部监听器
qs.addInternalSchedulerListener(this);
label0:
{
//protected JobExecutionContextImpl jec,job执行上下文
OperableTrigger trigger = (OperableTrigger)jec.getTrigger();
JobDetail jobDetail = jec.getJobDetail();
org.quartz.Trigger.CompletedExecutionInstruction instCode;
do
{
JobExecutionException jobExEx = null;
Job job = jec.getJobInstance();
try
{
begin();
}
catch(SchedulerException se)
{
qs.notifySchedulerListenersError((new StringBuilder()).append("Error executing Job (").append(jec.getJobDetail().getKey()).append(": couldn‘t begin execution.").toString(), se);
break label0;
}
try
{
if(!notifyListenersBeginning(jec))
break label0;
}
catch(VetoedException ve)
{
try
{
org.quartz.Trigger.CompletedExecutionInstruction instCode = trigger.executionComplete(jec, null);
qs.notifyJobStoreJobVetoed(trigger, jobDetail, instCode);
if(jec.getTrigger().getNextFireTime() == null)
qs.notifySchedulerListenersFinalized(jec.getTrigger());
complete(true);
}
catch(SchedulerException se)
{
qs.notifySchedulerListenersError((new StringBuilder()).append("Error during veto of Job (").append(jec.getJobDetail().getKey()).append(": couldn‘t finalize execution.").toString(), se);
}
break label0;
}
long startTime = System.currentTimeMillis();
long endTime = startTime;
try
{
log.debug((new StringBuilder()).append("Calling execute on job ").append(jobDetail.getKey()).toString());
//执行Job,关键
job.execute(jec);
endTime = System.currentTimeMillis();
}
catch(JobExecutionException jee)
{
endTime = System.currentTimeMillis();
jobExEx = jee;
getLog().info((new StringBuilder()).append("Job ").append(jobDetail.getKey()).append(" threw a JobExecutionException: ").toString(), jobExEx);
}
catch(Throwable e)
{
endTime = System.currentTimeMillis();
getLog().error((new StringBuilder()).append("Job ").append(jobDetail.getKey()).append(" threw an unhandled Exception: ").toString(), e);
SchedulerException se = new SchedulerException("Job threw an unhandled exception.", e);
qs.notifySchedulerListenersError((new StringBuilder()).append("Job (").append(jec.getJobDetail().getKey()).append(" threw an exception.").toString(), se);
jobExEx = new JobExecutionException(se, false);
}
//设置jJobExecutionContext运行时间
jec.setJobRunTime(endTime - startTime);
if(!notifyJobListenersComplete(jec, jobExEx))
break label0;
instCode = org.quartz.Trigger.CompletedExecutionInstruction.NOOP;
try
{
instCode = trigger.executionComplete(jec, jobExEx);
}
catch(Exception e)
{
SchedulerException se = new SchedulerException("Trigger threw an unhandled exception.", e);
qs.notifySchedulerListenersError("Please report this error to the Quartz developers.", se);
}
if(!notifyTriggerListenersComplete(jec, instCode))
break label0;
if(instCode == org.quartz.Trigger.CompletedExecutionInstruction.RE_EXECUTE_JOB)
{
jec.incrementRefireCount();
try
{
complete(false);
}
catch(SchedulerException se)
{
qs.notifySchedulerListenersError((new StringBuilder()).append("Error executing Job (").append(jec.getJobDetail().getKey()).append(": couldn‘t finalize execution.").toString(), se);
}
continue;
}
try
{
complete(true);
break;
}
catch(SchedulerException se)
{
qs.notifySchedulerListenersError((new StringBuilder()).append("Error executing Job (").append(jec.getJobDetail().getKey()).append(": couldn‘t finalize execution.").toString(), se);
}
} while(true);
//通知job执行完成
qs.notifyJobStoreJobComplete(trigger, jobDetail, instCode);
}
qs.removeInternalSchedulerListener(this);
break MISSING_BLOCK_LABEL_710;
Exception exception;
exception;
qs.removeInternalSchedulerListener(this);
throw exception;
}
protected JobExecutionContextImpl jec;//job执行上下文
protected QuartzScheduler qs;
protected TriggerFiredBundle firedTriggerBundle;
protected Scheduler scheduler;
protected volatile boolean shutdownRequested;
private final Logger log = LoggerFactory.getLogger(getClass());
}