Quartz1.8简单入门

package com.quartz.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;

public class HelloJob implements Job {
	public void run() throws SchedulerException, InterruptedException, ParseException{
		// 1. 通过工厂的到周期
		Scheduler sche = new StdSchedulerFactory().getScheduler();
		SimpleTrigger st = new SimpleTrigger("t1"); 	// 2.创建一个简单触发器
		st.setStartTime(new Date(2000L));//启动时间,当前时间 + date
		st.setRepeatCount(-1);// - 1 无限循环
		st.setRepeatInterval(1000L);//每1秒执行一次
		JobDetail detail = new JobDetail("hello",HelloJob.class);// 3. 创建 job 详情
		sche.scheduleJob(detail, st);// 4. 注册周期任务调度
		sche.start();// 5.启动
		System.out.println("-------- start() success ---------");
		Thread.sleep(100L*6000L);
		sche.shutdown();//停止
	}
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		System.out.println("test - -- - - - /*_*/ " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
	}
	//运行
	public static void main(String[] args) throws Exception, InterruptedException {
		new HelloJob().run();
	}
}

 

你可能感兴趣的:(Quartz1.8简单入门)