欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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();
}
}

}

相关标签: quartz