gpt4 book ai didi

java - Quartz PersistJobDataAfterExecution 执行后不存储

转载 作者:行者123 更新时间:2023-12-01 18:19:02 25 4
gpt4 key购买 nike

我使用quartz 2.2.1和mysql als jdbc store,我有一个像这样的简单工作:

package foo;

import org.quartz.*;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class FooJob2 implements Job {
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
int count = (int) jobExecutionContext.getJobDetail().getJobDataMap().get("foobar");
System.out.println("lala neu 3 " + count);
jobExecutionContext.getJobDetail().getJobDataMap().put("foobar", count++);

}
}

我这样安排作业,但是每当作业打印 foobar 编号时,它都不会增加。我必须做什么才能使作业持久化作业数据图?

public class TestStore {
public static void main(String[] args) throws SchedulerException, InterruptedException {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();

JobDataMap data = new JobDataMap();
data.put("foobar", 12);
// data.put("foobar", "12");

// define the job and tie it to our HelloJob class
JobDetail job = newJob(FooJob2.class)
.withIdentity("job6", "group1")
.storeDurably()
.usingJobData(data)
.build();

// Trigger the job to run now, and then repeat every 40 seconds
Trigger trigger = newTrigger()
.withIdentity("trigger6", "group1")
.startNow()
//.usingJobData(data)
.withSchedule(simpleSchedule()
.withIntervalInSeconds(1)
.repeatForever())
.build();


// Tell quartz to schedule the job using our trigger
Set<Trigger> triggers = new HashSet<>();
triggers.add(trigger);
try {
scheduler.scheduleJob(job, trigger);
} catch (SchedulerException se) {
System.out.println("update job");
scheduler.addJob(job, true);
}


// Thread.sleep(6000);
// scheduler.shutdown();
}
}

最佳答案

在行中使用++count

jobExecutionContext.getJobDetail().getJobDataMap().put("foobar", ++count);

关于java - Quartz PersistJobDataAfterExecution 执行后不存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28106086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com