public class MyJobTest {
public static void main(String[] args) throws SchedulerException,
ParseException {
startSchedule();
//resumeJob();
}
/**
* 开始一个simpleSchedule()调度
*/
public static void startSchedule() {
try {
// 1、创建一个JobDetail实例,指定Quartz
JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
// 任务执行类
.withIdentity("job1_1", "jGroup1")
// 任务名,任务组
.build();
//触发器类型
SimpleScheduleBuilder builder = SimpleScheduleBuilder
// 设置执行次数
.repeatSecondlyForTotalCount(5);
//CronScheduleBuilder builder = CronScheduleBuilder.cronSchedule("0/2 * * * * ?");
// 2、创建Trigger
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("trigger1_1", "tGroup1").startNow()
.withSchedule(builder)
.build();
// 3、创建Scheduler
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
// 4、调度执行
scheduler.scheduleJob(jobDetail, trigger);
try {
System.out.print(" 线程睡眠60000秒!\n");
Thread.sleep(60000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//关闭调度器
scheduler.shutdown();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
}
6000秒?