JobBuilder也可向任务传递数据,通常情况下,我们使用它就可向任务类发送数据了,如有特别复杂的传递参数,它提供了一个传递:JobDataMap对象的方法,当然这个要根据个人使用习惯来说了呀
它重载了方法usingJobData(),如下图:
JobDetail job = newJob(StatefulDumbJob.class)
.withIdentity("statefulJob1", "group1")
.usingJobData(StatefulDumbJob.EXECUTION_DELAY, 10000L)//传递数据
.build();
SimpleTrigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.startAt(startTime)
.withSchedule(simpleSchedule()
.withIntervalInSeconds(3)
.repeatForever())
.build();
Date ft = sched.scheduleJob(job, trigger);
log.error("任务key: "+job.getKey() + ",执行运行时间: " + sdf.format(ft) +
",触发器重复执行次数: " + trigger.getRepeatCount() +
",触发器执行时间: " + trigger.getRepeatInterval() / 1000 + " seconds");
在任务类一样可取出:
JobDataMap map = context.getJobDetail().getJobDataMap();
int executeCount = 0;
if (map.containsKey(NUM_EXECUTIONS)) {
executeCount = map.getInt(NUM_EXECUTIONS);
}
executeCount++;
map.put(NUM_EXECUTIONS, executeCount);
- 大小: 11.6 KB
分享到:
相关推荐
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.impl.StdSchedulerFactory; public...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.impl.StdSchedulerFactory; public...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.impl.StdSchedulerFactory; public...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.TriggerBuilder; // 创建...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org....
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerBuilder; JobDetail jobDetail = JobBuilder.newJob(MyJob.class) .withIdentity("myJob", ...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.SimpleScheduleBuilder; import org.quartz.Trigger; import ...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.context.annotation.Bean; import org.springframework....
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.beans.factory.annotation...
IJobDetail job = JobBuilder.Create().Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("myTrigger") .WithCronSchedule("0 * * * * ?") // 每分钟触发 .Build(); scheduler.ScheduleJob...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.context.annotation....
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.beans.factory.annotation...
return JobBuilder.newJob(MyTask.class) .withIdentity("myTask", "group1") .build(); } @Bean public CronTrigger myTaskTrigger() { return TriggerBuilder.newTrigger() .withIdentity("myTaskTrigger...
import org.quartz.JobBuilder; import org.quartz.TriggerBuilder; import org.quartz.CronScheduleBuilder; public class QuartzExample { public static void main(String[] args) throws Exception { // 创建...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.SchedulerFactory; import org....
JobDetail job = JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "group1") // 设置Job的名字和组名 .build(); // 创建Trigger Trigger trigger = TriggerBuilder.newTrigger() .withIdentity(...
return JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "group1") .build(); } @Bean public CronTrigger myCronTrigger() { return TriggerBuilder.newTrigger() .withIdentity("myTrigger", ...
import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.context.annotation.Bean; import org.springframework....
return JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "group1") // 定义Job的名字和组名 .build(); } @Bean public Trigger myJobTrigger(JobDetail myJob) { return TriggerBuilder.newTrigger...
### Java框架介绍: Quartz从入门到进阶 #### 一、Quartz简介 Quartz是一个完全由Java编写的开源作业调度框架,适用于多种Java应用程序环境,包括但不限于J2SE、Web应用以及J2EE应用服务器。它提供了一种简单而灵活...