更新现有的 JobDataMap
我有一份已经安排好的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在石英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
.我遇到了类似的问题:我有一个第二个触发器,它触发一个在作业数据映射中的队列上工作的有状态作业。每次作业触发时,它都会从队列中进行轮询并对轮询的元素执行一些工作。每次执行作业时,队列都会少一个元素(队列会在作业内正确更新)。当队列为空时,作业会自行取消调度。
我希望能够从外部更新正在进行的作业/触发器的参数列表,以便为队列提供更多参数。然而,仅仅检索数据映射并更新队列是不够的(以下执行显示队列未更新)。问题在于,Quartz 仅在执行后更新作业实例的作业数据映射。
这是我找到的解决方案:
最后一行指示 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:
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.
请参阅http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson03。 html:
See http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson03.html: