上一篇介绍了通过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();