Quartz任务调度模型实例

#首先导入:quartz-all-1.6.5.jar、commons-collections-3.2.jar、commons-logging-1.1.jar、log4j-1.2.15.jar

import java.text.ParseException; import org.quartz.CronTrigger; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.impl.StdSchedulerFactory; class Test { public Scheduler createScheduler() throws Exception { SchedulerFactory sf = new StdSchedulerFactory("Quartz.properties"); Scheduler scheduler = sf.getScheduler(); scheduler.scheduleJob(createJobDetail(), createCronTrigger()); return scheduler; } private JobDetail createJobDetail() { JobDetail job = new JobDetail(DemoJob.class.getName(), Scheduler.DEFAULT_GROUP, DemoJob.class); return job; } private CronTrigger createCronTrigger() throws ParseException { CronTrigger trigger = new org.quartz.CronTrigger("DEFAULT", null); trigger.setJobName(DemoJob.class.getName()); trigger.setCronExpression("0 0 12 * * ?"); return trigger; } } //==================================================== import java.util.Date; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; public class DemoJob implements Job { public static void main(String[] args) throws Exception { Test test = new Test(); test.createScheduler().start(); } public void execute(JobExecutionContext arg0) throws JobExecutionException { System.out.println("demo output :" + new Date()); } } //======在classpath下创建Quartz.properties============= org.quartz.scheduler.instanceName=DefaultQuartzScheduler # Set thread count to 1 to force Triggers scheduled for the same time to # to be ordered by priority. org.quartz.threadPool.threadCount=1 org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore

你可能感兴趣的:(thread,exception,quartz,任务调度,output,triggers)