1 17 18 package org.quartz.examples.example6; 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 40 public class JobExceptionExample { 41 42 public void run() throws Exception { 43 Log log = LogFactory.getLog(JobExceptionExample.class); 44 45 log.info("------- Initializing ----------------------"); 46 47 SchedulerFactory sf = new StdSchedulerFactory(); 49 Scheduler sched = sf.getScheduler(); 50 51 log.info("------- Initialization Complete ------------"); 52 53 log.info("------- Scheduling Jobs -------------------"); 54 55 57 long ts = TriggerUtils.getNextGivenSecondDate(null, 15).getTime(); 59 60 JobDetail job = new JobDetail("badJob1", "group1", BadJob1.class); 64 SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1", 65 new Date (ts), null, SimpleTrigger.REPEAT_INDEFINITELY, 3000L); 66 Date ft = sched.scheduleJob(job, trigger); 67 log.info(job.getFullName() + " will run at: " + ft + " and repeat: " 68 + trigger.getRepeatCount() + " times, every " 69 + trigger.getRepeatInterval() / 1000 + " seconds"); 70 71 job = new JobDetail("badJob2", "group1", BadJob2.class); 75 trigger = new SimpleTrigger("trigger2", "group1", new Date (ts), null, 76 SimpleTrigger.REPEAT_INDEFINITELY, 3000L); 77 ft = sched.scheduleJob(job, trigger); 78 log.info(job.getFullName() + " will run at: " + ft + " and repeat: " 79 + trigger.getRepeatCount() + " times, every " 80 + trigger.getRepeatInterval() / 1000 + " seconds"); 81 82 log.info("------- Starting Scheduler ----------------"); 83 84 sched.start(); 86 87 log.info("------- Started Scheduler -----------------"); 88 89 try { 90 Thread.sleep(60L * 1000L); 92 } catch (Exception e) { 93 } 94 95 log.info("------- Shutting Down ---------------------"); 96 97 sched.shutdown(true); 98 99 log.info("------- Shutdown Complete -----------------"); 100 101 SchedulerMetaData metaData = sched.getMetaData(); 102 log.info("Executed " + metaData.numJobsExecuted() + " jobs."); 103 } 104 105 public static void main(String [] args) throws Exception { 106 107 JobExceptionExample example = new JobExceptionExample(); 108 example.run(); 109 } 110 111 } | Popular Tags |