Sample code後有一段是展示如何重新啟動排程及設定排程時間。
這段Sample code是使用Spring framework。
public class LogAnalysisJob extends QuartzJobBean {
private LogAnalysisBO bo;
public void setBo(MyBO bo) {
this.bo = bo;
}
protected void executeInternal(JobExecutionContext c)
throws JobExecutionException {
Scheduler sc = c.getScheduler();
try {
List l = sc.getCurrentlyExecutingJobs();
if (l.size() <= 1) { //限定目前的只有1個bo被執行
bo.exe();//真正執行企業邏輯的部份
}
SimpleTriggerBean t = (SimpleTriggerBean) c.getTrigger();
if (count > 10) {
t.setRepeatInterval(t.getRepeatInterval() + 3000);//如果排程執行超過10次, 每次執行間隔就延長3秒
sc.rescheduleJob(t.getName(), c.getJobDetail().getGroup(), t);
count = 0;
}
count++;
} catch (SchedulerException e) {
e.printStackTrace();
}
private static int count;
}