quartz 作业调度练习

/**
 * 作业调度实例
 * @version QuartzReport.java v. 1.0.0 2012-8-6
 * @author FengXiYang copyright (c) 2012 北京叁加伍软件技术有限公司 http://www.3jia5.com

 */

//每一个任务必须实现job接口,

public class QuartzReport implements Job {
    @Override
    public void execute(JobExecutionContext cntxt) throws JobExecutionException {
        // TODO Auto-generated method stub
        System.out.println( cntxt.getJobDetail().getJobDataMap().get("name")+ 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);

            //map存放任务公共数据,供每一个任务对该map操作,如入库....

            jobDetail.getJobDataMap().put("name","lucy");

            CronTrigger trigger = new CronTrigger(" Income Report "," Report Generation ");

            //每5秒执行一次,每1分钟执行一次为trigger.setCronExpression(" 0 0/1 * * * ? ");

            trigger.setCronExpression("0/5 * * * * ? " );
            sched.scheduleJob(jobDetail, trigger);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

你可能感兴趣的:(quartz 作业调度练习)