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?

- 6,594
- 9
- 63
- 100

- 179,021
- 58
- 319
- 408
3 Answers
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
.

- 588,226
- 146
- 1,060
- 1,140
-
But in which table can we find the JobDataMap information, I checked all the tables but i cldn't find them. – Sangram Anand Jul 12 '12 at 06:55
-
Is it the Job_data columns of QRTZ_JOB_DETAILS table? – Sangram Anand Jul 12 '12 at 07:08
-
I don't know, I haven't configured database persistence of jobs – Bozho Jul 13 '12 at 15:13
-
Yes the info can be found in QRTZ_JOB_DETAILS tables. – iec2011007 Jul 31 '18 at 07:28
-
the tricky part is to write down the both annotations PersistJobDataAfterExecution and DisallowConcurrentExecution in the job class – Antonio Martin May 10 '19 at 12:56
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.

- 181
- 3
-
There seems to be a problem with this with the latest version of Quartz (2.6.10?) – Nigel Sheridan-Smith Mar 13 '13 at 01:24
-
Sorry - that's version 2.1.7... worked ok with 2.1.6 previously – Nigel Sheridan-Smith Mar 13 '13 at 20:31
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.

- 8,550
- 5
- 32
- 51
-
5but what if I want to update a job from outside of an execution? e.g. from JMX? – Simon Gibbs Feb 07 '13 at 15:12