/**
*
*/
package com.test;
import java.text.ParseException;
import java.util.Date;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
/**
* @author GBK
*
*/
public class Test {
/**
*
*/
public Test() {
// TODO Auto-generated constructor stub
}
public void TestSimple() throws SchedulerException{
// TODO Auto-generated method stub
Scheduler scheduler = null;
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
scheduler = schedulerFactory.getScheduler();
JobDetail jobDetail =
new JobDetail("jobDetail-s1", "jobDetailGroup-s1", TestJob.class);//创建作业
SimpleTrigger simpleTrigger =
new SimpleTrigger("simpleTrigger", "triggerGroup-s1");//创建一个触发器
//设置作业启动时间
long ctime = System.currentTimeMillis();
simpleTrigger.setStartTime(new Date(ctime));
//设置作业执行间隔
simpleTrigger.setRepeatInterval(1000);
//设置作业执行次数
simpleTrigger.setRepeatCount(10);
//设置作业执行优先级默认为5
//simpleTrigger.setPriority(10);
//作业和触发器设置到调度器中
scheduler.scheduleJob(jobDetail, simpleTrigger);
//启动调度器
scheduler.start();
// scheduler.shutdown();//关闭
}
public void TestCron() throws SchedulerException, ParseException{
Scheduler scheduler = null;
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
scheduler = schedulerFactory.getScheduler();
JobDetail jobDetail =
new JobDetail("jobDetail-s1", "jobDetailGroup-s1", TestJob.class);//创建作业
CronTrigger cronTrigger = new CronTrigger("cronTrigger",
"triggerGroup1");
String cronExpression="0 0/1 * * * ?";
cronTrigger.setCronExpression(cronExpression);
scheduler.scheduleJob(jobDetail, cronTrigger);
scheduler.start();
}
/**
* @param args
* @throws SchedulerException
* @throws ParseException
*/
public static void main(String[] args) throws SchedulerException, ParseException {
Test test=new Test();
// test.TestCron();
test.TestSimple();
}
}