1 17 18 package org.quartz.examples.example5; 19 20 import java.util.Date ; 21 22 import org.quartz.JobDetail; 23 import org.quartz.Scheduler; 24 import org.quartz.SchedulerFactory; 25 import org.quartz.SchedulerMetaData; 26 import org.quartz.SimpleTrigger; 27 import org.quartz.TriggerUtils; 28 import org.quartz.impl.StdSchedulerFactory; 29 30 import org.apache.commons.logging.LogFactory; 31 import org.apache.commons.logging.Log; 32 33 56 public class MisfireExample { 57 58 59 public void run() throws Exception { 60 Log log = LogFactory.getLog(MisfireExample.class); 61 62 log.info("------- Initializing -------------------"); 63 64 SchedulerFactory sf = new StdSchedulerFactory(); 66 Scheduler sched = sf.getScheduler(); 67 68 log.info("------- Initialization Complete -----------"); 69 70 log.info("------- Scheduling Jobs -----------"); 71 72 74 long ts = TriggerUtils.getNextGivenSecondDate(null, 15).getTime(); 76 77 JobDetail job = new JobDetail("statefulJob1", "group1", 80 StatefulDumbJob.class); 81 job.getJobDataMap().put(MisfireJob.EXECUTION_DELAY, 10000L); 82 SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1", 83 new Date (ts), null, 84 SimpleTrigger.REPEAT_INDEFINITELY, 3000L); 85 Date ft = sched.scheduleJob(job, trigger); 86 log.info(job.getFullName() + 87 " will run at: " + ft + 88 " and repeat: " + trigger.getRepeatCount() + 89 " times, every " + trigger.getRepeatInterval() / 1000 + " seconds"); 90 91 job = new JobDetail("statefulJob2", "group1", StatefulDumbJob.class); 94 job.getJobDataMap().put(MisfireJob.EXECUTION_DELAY, 10000L); 95 trigger = new SimpleTrigger("trigger2", "group1", 96 new Date (ts), null, 97 SimpleTrigger.REPEAT_INDEFINITELY, 3000L); 98 trigger 99 .setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT); 100 ft = sched.scheduleJob(job, trigger); 101 log.info(job.getFullName() + 102 " will run at: " + ft + 103 " and repeat: " + trigger.getRepeatCount() + 104 " times, every " + trigger.getRepeatInterval() / 1000 + " seconds"); 105 106 log.info("------- Starting Scheduler ----------------"); 107 108 sched.start(); 110 111 log.info("------- Started Scheduler -----------------"); 112 113 try { 114 Thread.sleep(600L * 1000L); 116 } catch (Exception e) { 117 } 118 119 log.info("------- Shutting Down ---------------------"); 120 121 sched.shutdown(true); 122 123 log.info("------- Shutdown Complete -----------------"); 124 125 SchedulerMetaData metaData = sched.getMetaData(); 126 log.info("Executed " + metaData.numJobsExecuted() + " jobs."); 127 } 128 129 130 131 public static void main(String [] args) throws Exception { 132 133 MisfireExample example = new MisfireExample(); 134 example.run(); 135 } 136 137 } | Popular Tags |