quartz---的jobDateil,Trigger的存值
package com.imooc.demo.helloQuartz; import java.text.SimpleDateFormat;
import java.util.Date; import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory; public class HelloScheduler { public static void main(String[] args) throws SchedulerException {
// 创建一个jobDatail实例,将该实力与helloJob绑定
JobDetail detail = JobBuilder.newJob(HelloJob.class).withIdentity("myJob").usingJobData("message", "hi! myjob")
.usingJobData("FloatJobValue", 3.14F).build(); // 创建一个Trigger实例,定义该job立即执行,并且在每隔2秒重复执行
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1")
.usingJobData("message", "hi! myTrigger").usingJobData("DoubleTriggerValue", 2.0D).startNow()
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2).repeatForever()).build();
// 创建Scheduler实例
SchedulerFactory factory = new StdSchedulerFactory();
Scheduler scheduler = factory.getScheduler();
scheduler.start();
Date date = new Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("Current Exec Time Is:" + sf.format(date) + "-----");
// 把jobDetail和Trigger与scheuler绑定在一起
scheduler.scheduleJob(detail, trigger);
}
}
package com.imooc.demo.helloQuartz; import java.text.SimpleDateFormat;
import java.util.Date; import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.TriggerKey; public class HelloJob implements Job { private String message;
private Float FloatJobValue;
private Double DoubleTriggerValue; public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
} public Float getFloatJobValue() {
return FloatJobValue;
} public void setFloatJobValue(Float floatJobValue) {
FloatJobValue = floatJobValue;
} public Double getDoubleTriggerValue() {
return DoubleTriggerValue;
} public void setDoubleTriggerValue(Double doubleTriggerValue) {
DoubleTriggerValue = doubleTriggerValue;
} @Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// 打印当前执行的时间,格式为2017-05-06 00:00:00
Date date = new Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("Current Exec Time Is:" + sf.format(date));
// 编写具体业务逻辑
// 获取存入HelloScheduler信息
JobKey key = context.getJobDetail().getKey();
System.out.println("My Job name and group are:" + key.getName() + ":" + key.getGroup()); TriggerKey keys = context.getTrigger().getKey();
System.out.println("My Trigger name and group are:" + keys.getName() + ":" + keys.getGroup()); //JobDataMap dataMap = context.getMergedJobDataMap();
System.out.println("TriggerDouble:" + DoubleTriggerValue + "\r" + "TriggerMessage:" + message + "\r"
+ "JobFloat:" + FloatJobValue);
System.out.println("-----------------");
} }
package com.imooc.demo.helloQuartz; import java.text.SimpleDateFormat;
import java.util.Date; import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.TriggerKey; public class HelloJob implements Job { private String message;
private Float FloatJobValue;
private Double DoubleTriggerValue; public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
} public Float getFloatJobValue() {
return FloatJobValue;
} public void setFloatJobValue(Float floatJobValue) {
FloatJobValue = floatJobValue;
} public Double getDoubleTriggerValue() {
return DoubleTriggerValue;
} public void setDoubleTriggerValue(Double doubleTriggerValue) {
DoubleTriggerValue = doubleTriggerValue;
} @Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// 打印当前执行的时间,格式为2017-05-06 00:00:00
Date date = new Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("Current Exec Time Is:" + sf.format(date));
// 编写具体业务逻辑
// 获取存入HelloScheduler信息
JobKey key = context.getJobDetail().getKey();
System.out.println("My Job name and group are:" + key.getName() + ":" + key.getGroup()); TriggerKey keys = context.getTrigger().getKey();
System.out.println("My Trigger name and group are:" + keys.getName() + ":" + keys.getGroup()); //JobDataMap dataMap = context.getMergedJobDataMap();
System.out.println("TriggerDouble:" + DoubleTriggerValue + "\r" + "TriggerMessage:" + message + "\r"
+ "JobFloat:" + FloatJobValue);
System.out.println("-----------------");
} }
jobDateil,Trigger的存值,取值。
1.JobDateMap的取值;
2.set和get注入方法取值;