I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes it takes just few seconds to execute, but as data gets bigger I'm sure it run for 20 seconds or more.
How can I prevent Quartz from firing/triggering the job while one instance is still being executed? Firing 2 jobs performing same operations on a database would not be so good. Is there a way I can do some kind of synchronization?
Best Answer
Quartz 1
If you change your class to implement StatefulJob instead of Job, Quartz will take care of this for you. From the StatefulJob javadoc:
StatefulJob extends Job and does not add any new methods, so all you need to do to get the behaviour you want is change this:
To this:
Quartz 2
In version 2.0 of Quartz,
StatefulJob
is deprecated. It is now recommended to use annotations instead, e.g.