java quartz 源码_Quartz任务调度源码分析

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());

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值