Quartz任务调度
程序员文章站
2022-05-24 19:05:50
...
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();
}
}
}
上一篇: oracle更新数据方式