日期:2014-05-18 浏览次数:20686 次
package com.syj; import java.text.ParseException; import java.util.Date; import org.quartz.CronTrigger; import org.quartz.Job; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.impl.StdSchedulerFactory; /** * <p> * Title: Quartz小demo * </p> * * * @author 孙钰佳 * @main sunyujia@yahoo.cn * @blog http://blog.csdn.net/sunyujia/ * @date Oct 29, 2008 7:41:01 PM */ 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/5 * * * * ? "); return trigger; } } 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()); } }