凉水代码

Code Cold Water

导航

Quartz入门

Posted on 2010-11-14 20:24  凉水代码  阅读(193)  评论(0编辑  收藏  举报

public class TestJob implements StatefulJob {

	@Override
	public void execute(JobExecutionContext jectx) throws JobExecutionException {
		System.out.println("do some thing");
	}

	public static void main(String[] args) throws SchedulerException, ParseException {
		SchedulerFactory sf = new StdSchedulerFactory(); // 1 获得调度器
		Scheduler scheduler = sf.getScheduler();

		JobDetail job = new JobDetail("hello_world_job", TestJob.class); // 2创建任务

		// s m h d M w
		Trigger triger = new CronTrigger("xtrigger", null, "* * * * * ?"); // 3创建定时触发器
		// triger =triger = TriggerUtils.makeSecondlyTrigger();
		triger.setName("x_trigger");

		scheduler.scheduleJob(job, triger); // 4 设定任务

		scheduler.start(); // 5 启动

	}
}