1 17 18 package org.quartz.examples.example1; 19 20 import java.util.Date ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.quartz.JobDetail; 25 import org.quartz.Scheduler; 26 import org.quartz.SchedulerFactory; 27 import org.quartz.SimpleTrigger; 28 import org.quartz.TriggerUtils; 29 import org.quartz.impl.StdSchedulerFactory; 30 31 37 public class SimpleExample { 38 39 40 public void run() throws Exception { 41 Log log = LogFactory.getLog(SimpleExample.class); 42 43 log.info("------- Initializing ----------------------"); 44 45 SchedulerFactory sf = new StdSchedulerFactory(); 47 Scheduler sched = sf.getScheduler(); 48 49 log.info("------- Initialization Complete -----------"); 50 51 log.info("------- Scheduling Jobs -------------------"); 52 53 Date runTime = TriggerUtils.getEvenMinuteDate(new Date ()); 55 56 JobDetail job = new JobDetail("job1", "group1", HelloJob.class); 58 59 SimpleTrigger trigger = 61 new SimpleTrigger("trigger1", "group1", runTime); 62 63 sched.scheduleJob(job, trigger); 65 log.info(job.getFullName() + " will run at: " + runTime); 66 67 sched.start(); 70 log.info("------- Started Scheduler -----------------"); 71 72 log.info("------- Waiting 90 seconds... -------------"); 75 try { 76 Thread.sleep(90L * 1000L); 78 } catch (Exception e) { 80 } 81 82 log.info("------- Shutting Down ---------------------"); 84 sched.shutdown(true); 85 log.info("------- Shutdown Complete -----------------"); 86 } 87 88 public static void main(String [] args) throws Exception { 89 90 SimpleExample example = new SimpleExample(); 91 example.run(); 92 93 } 94 95 } | Popular Tags |