package com.cavaness.quartzbook.chapter3;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory;
/**
* 编程式的调度器,用同一个作业类做了不同的配置,相当于运行多个作业
* 创建调度器,并调度作业
* @author Kevin
*
*/
public class Listing_3_5 {
private static Log log = LogFactory.getLog(Listing_3_5.class);
/**
* 创建调度器
* @throws SchedulerException
*/
public Scheduler createsScheduler() throws SchedulerException {
try {
return StdSchedulerFactory.getDefaultScheduler();
} catch (SchedulerException e) {
log.error("调度器创建失败!", e);
throw e;
}
}
public static void main(String[] args) throws SchedulerException {
Listing_3_5 listing_3_5 = new Listing_3_5();
Scheduler scheduler = null;
try {
scheduler = listing_3_5.createsScheduler();
} catch (SchedulerException e) {
log.error("创建调度器失败!", e);
throw e;
}
try {
scheduler.start();
} catch (SchedulerException e) {
log.error("启动调度器失败!", e);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
log.info("调度器启动成功,启动时间:" + simpleDateFormat.format(new Date()));
}
}