1 package cn.bd.quartz.test;
2
3 import java.text.ParseException;
4 import java.util.Date;
5
6 import org.quartz.CronTrigger;
7 import org.quartz.JobDetail;
8 import org.quartz.Scheduler;
9 import org.quartz.SchedulerException;
10 import org.quartz.SchedulerFactory;
11 import org.quartz.SimpleTrigger;
12 import org.quartz.impl.StdSchedulerFactory;
13
14 import cn.bd.quartz.RemindJob;
15
16 public class TestJob {
17 public void doRemind() throws SchedulerException, InterruptedException, ParseException{
18 //创建一个任务
19 JobDetail job=new JobDetail("remindJob","group1",RemindJob.class);
20
21 //创建一个触发器
22 /*SimpleTrigger simTrig=new SimpleTrigger("trigRemindJob",SimpleTrigger.REPEAT_INDEFINITELY,3000);*/
23 /*simTrig.setStartTime(new Date(System.currentTimeMillis()+1000));*/
24 CronTrigger simTrig=new CronTrigger("remindJob","group1","1/3 * * * * ?");
25
26 //创建一个调度者
27 SchedulerFactory sfc=new StdSchedulerFactory();
28 Scheduler sched=sfc.getScheduler();
29 //注册并进行调度
30 sched.scheduleJob(job,simTrig);
31 sched.start();
32 Thread.sleep(10000);
33 sched.shutdown();
34 }
35
36 public static void main(String[] args) throws SchedulerException, InterruptedException, ParseException {
37 new TestJob().doRemind();
38 }
39 }