Quartz入門例

1759 ワード

// job
public class CallGirl implements Job{

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		System.out.println(" ...");
		System.out.println("getTrigger().getName():"+context.getTrigger().getName());
		
	}

}

 
package com.mtea.qtz.test;

import java.util.Date;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;

import com.mtea.qtz.job.CallGirl;

public class QuartzMainer {
	public static void main(String[] args) throws SchedulerException {
		
		Scheduler handsomeMan = new StdSchedulerFactory().getScheduler();
		
		//CallGirl.class  
		JobDetail concerneGirl = new JobDetail(" ", "group1", CallGirl.class);
		
		//10  ,2000L  
		SimpleTrigger momentTrigger = new SimpleTrigger("trigger1", "group1", new Date(), null, 10, 2000L);
		
		
		//way 2
		// , 100000000 
		long startTime=System.currentTimeMillis();
		SimpleTrigger momentTrigger2= new SimpleTrigger("trigger2", "group1");
		momentTrigger2.setStartTime(new Date(startTime));
		momentTrigger2.setEndTime(new Date(startTime+6000L));
		momentTrigger2.setRepeatCount(10);
		momentTrigger2.setRepeatInterval(1000L);
		
		// Trigger job
		handsomeMan.scheduleJob(concerneGirl, momentTrigger);  
		
		// 
		handsomeMan.start();
	}

}