Test类
package test;
import java.text.ParseException;
import java.util.Date;
import job.RemaindJob;
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;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// 创建任务
JobDetail jobDetail = new JobDetail("myjob1", RemaindJob.class);
//添加参数
jobDetail.getJobDataMap().put("user", "Tom");
// 创建简单触发器,REPEAT_INDEFINITELY:无限重复
/*SimpleTrigger simpleTri = new SimpleTrigger("trigger1",
SimpleTrigger.REPEAT_INDEFINITELY, 500);*/
CronTrigger cronTri;
try {
//Cron表达式
cronTri = new CronTrigger("cronTri", "cron", "1/1 * * * * ?");
// 设置触发器开始延迟时间
cronTri.setStartTime(new Date(System.currentTimeMillis() + 1000));
// 创建调度工厂
SchedulerFactory sf = new StdSchedulerFactory();
// 获取调度器
Scheduler scheduler;
scheduler = sf.getScheduler();
// 用调度器关联绑定触发器和任务
scheduler.scheduleJob(jobDetail, cronTri);
// 启动
scheduler.start();
Thread.sleep(9000);
// 停止
scheduler.shutdown();
} catch (ParseException e1) {
e1.printStackTrace();
} catch (SchedulerException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}