更新现有的 JobDataMap

发布于 2024-09-01 07:32:12 字数 196 浏览 6 评论 0原文

我有一份已经安排好的 Quartz 工作。我想更新与之关联的 JobDataMap。如果我使用 JobDataMap jobDataMap = Scheduler.getJobDetail(....).getJobDataMap() 获得 JobDataMap,该地图是否“实时”? IE。如果我更改它,它会保留在调度程序中吗?如果没有,我该如何坚持?

I have a Quartz job that has already been scheduled. I want to update the JobDataMap associated with it. If I get a JobDataMap with JobDataMap jobDataMap = scheduler.getJobDetail(....).getJobDataMap(), is that map "live"? ie. if I change it, will it be persisted in the scheduler? If not, how do I persist it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅暮の光 2024-09-08 07:32:13

在石英2.0中。 StatefulJob 已弃用。为了持久保存作业数据映射,请在作业类上使用@PersistJobDataAfterExecution。它通常与@DisallowConcurrentExecution 一起使用。

In quartz 2.0. StatefulJob is deprecated. In order to persist the job data map, use @PersistJobDataAfterExecution on the job class. It usually goes with @DisallowConcurrentExecution.

落日海湾 2024-09-08 07:32:13

我遇到了类似的问题:我有一个第二个触发器,它触发一个在作业数据映射中的队列上工作的有状态作业。每次作业触发时,它都会从队列中进行轮询并对轮询的元素执行一些工作。每次执行作业时,队列都会少一个元素(队列会在作业内正确更新)。当队列为空时,作业会自行取消调度。

我希望能够从外部更新正在进行的作业/触发器的参数列表,以便为队列提供更多参数。然而,仅仅检索数据映射并更新队列是不够的(以下执行显示队列未更新)。问题在于,Quartz 仅在执行后更新作业实例的作业数据映射。

这是我找到的解决方案:

JobDetail jobDetail = scheduler.getJobDetail("myJob", "myGroup");
jobDetail.getJobDataMap.put("jobQueue", updatedQueue);
scheduler.addJob(jobDetail, true);

最后一行指示 Quartz 将存储的作业替换为您提供的作业。下次作业被触发时,它将看到更新后的队列。

I had a similar problem: I have a secondly trigger which fires a stateful job that works on a queue in the job's data map. Every time the job fires, it polls from the queue and performs some work on the polled element. With each job execution, the queue has one less element (the queue is updated correctly from within the job). When the queue is empty, the job unschedules itself.

I wanted to be able to externally update the list of arguments of an ongoing job/trigger to provide more arguments to the queue. However, just retrieving the data map and updating the queue was not enough (the following execution shows the queue is not updated). The problem is that Quartz only updates the job data map of a job instance after execution.

Here's the solution I found:

JobDetail jobDetail = scheduler.getJobDetail("myJob", "myGroup");
jobDetail.getJobDataMap.put("jobQueue", updatedQueue);
scheduler.addJob(jobDetail, true);

The last line instructs Quartz to replace the stored job with the one you are providing. The next time the job is fired it will see the updated queue.

你是暖光i 2024-09-08 07:32:13

请参阅http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson03。 html

Job 实例可以定义为
“有状态”或“无状态”。
无状态作业只有其
JobDataMap 按其当时的状态存储
添加到调度程序。这意味着
对内容所做的任何更改
执行期间作业数据映射的
的工作将会丢失,并且不会
下次工作时看到
执行。

...有状态的工作恰恰相反 -
其JobDataMap在之后重新存储
作业的每次执行。

通过让 Job 实现 StatefulJob 将其“标记”为有状态
界面,而不是作业
界面。

See http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson03.html:

A Job instance can be defined as
"stateful" or "non-stateful".
Non-stateful jobs only have their
JobDataMap stored at the time they are
added to the scheduler. This means
that any changes made to the contents
of the job data map during execution
of the job will be lost, and will not
seen by the job the next time it
executes.

...a stateful job is just the opposite -
its JobDataMap is re-stored after
every execution of the job.

You 'mark' a Job as stateful by having it implement the StatefulJob
interface, rather than the Job
interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文