Quartz, every execution of job,job is always a completely new object, but if the job implements the Org.quartz.StatefulJob interface instead of the job interface.
At this point the jobdatamap of Jobdetail will share an object. Note: When implementing stateful interfaces, Statefuljob, only jobdetail Jobdatamap are shared, others, such as the job itself, trigger, and so on, are still completely new objects each time they are executed. So, only Jobdetail's jobdatamap are shared, other Trigger.getjobdatamap (), Context.getmergedjobdatamap (), and so on these jobdatamap, still new
The following documents are referenced:
Use a stateful Job
The Quartz framework provides a ORG.QUARTZ.STATEFULJOB interface for this when you need to maintain state between Job executions in two times. The Statefuljob interface simply expands the Job interface and does not include a new method. You just need to implement the Statefuljob interface simply by using the same execute () method as the Job interface. If you have an existing job class, all you have to do is change the job interface to Org.quartz.StatefulJob.
There are two key differences in the use of jobs and statefuljob in the framework. First,Jobdatamap is re-persisted to Jobstore after each execution . This ensures that your Job data changes until the next execution is still maintained.
Change the status of a Job Jobdatamap
You can simply modify the Jobdatamap by using the map's put () method in a stateful Job. Any data that already exists will be overwritten with the new data. You can also do this for stateless jobs, but because Jobdatamap does not persist for stateless jobs, the data is not saved. Data modifications to the Jobdatamap on Trigger and Jobexecutioncontext are not preserved. |
Another significant difference between stateless and stateful jobs is that two or more stateful Jobdetail instances cannot be executed concurrently. It says you created and registered a stateful jobdetail to Scheduler. You also set up two Trigger to trigger the JOB: one for every five minutes, and the other for every five minutes Kushiro trigger. If these two Trigger try to trigger the Job at the same time, the framework does not allow this to happen. The second Trigger will always be blocked until the first one is over.
This creates the need to handle JOBDATAMAP storage. Because Jobdatamap storage is accompanied by jobdetail, and Jobdetail defines a Job instance, thread safety issues must be included in the scope of our consideration. Only one thread can run and update the JOBDATAMAP store at the same time. However, since the first Trigger has the opportunity to update the store before the second one tries to execute the JOB, the data can be faulted. It might even be possible to have a second Trigger before the first one is done (depending on what your Job is doing), and then there may be strange results.
Because of these differences, you should be cautious when you use Statefuljob. When you need to avoid concurrent execution of a job, a stateful job is your simplest bargaining chip. In the world of the Java EE, the word "state" has already caused some negative effects, but not for Quartz.
Quartz a state of Jobdatamap