package com.quartz.test;
import java.util.Date;
import org.quartz.CronTrigger;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
public class QuartzReport implements Job {
/**/ /* 重载该函数 */
public void execute(JobExecutionContext cntxt) throws JobExecutionException {
System.out.println( " Generating report - "
+ cntxt.getJobDetail().getJobDataMap().get( "type" )
+ new Date());
}
public static void main(String[] args)
{
try
{
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
sched.start();
JobDetail jobDetail = new JobDetail( " Income Report " ,
" Report Generation " , QuartzReport. class );
jobDetail.getJobDataMap().put( "type" , "FULL" );
CronTrigger trigger = new CronTrigger( "Income Report" ,
"Report Generation");
//每天9:00执行一次
trigger.setCronExpression( "0 0 9 * * ?");
sched.scheduleJob(jobDetail, trigger);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Quartz任务调度
最新推荐文章于 2024-07-25 09:25:27 发布