Quartz使用二 通过属性传递数据


上一篇介绍了通过context.getJobDetail().getJobDataMap()方式获取传递的数据,其实可以通过定义属性来传递参数

package org.tonny.quartz;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class ThirdJob implements Job
{

    // 通过set,get形式获取jobdetail传递的参数
    private String name;
    private double height;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException
    {
        /**
         * 执行具体的任务
         */
        // 获取传递的参数
        System.out.println(name);
        System.out.println(height);
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public double getHeight()
    {
        return height;
    }

    public void setHeight(double height)
    {
        this.height = height;
    }

}

 

 

调度器中传输数据

// 创建一个JobDetail实例,将该实例与HelloJob Class绑定
        JobDetail jobDetail = JobBuilder
                .newJob(ThirdJob.class)
                .withIdentity("ThirdJob", "ThirdGroup")
                .usingJobData("name", "北堂一刀")
                .usingJobData("height", 175.0D)
                .build();
        

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM