Ensure that Spring Quartz job execution doesn't overlap

后端 未结 7 1410
迷失自我
迷失自我 2020-11-28 23:12

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 sec

7条回答
  •  伪装坚强ぢ
    2020-11-28 23:32

    Just in case anyone references this question, StatefulJob has been deprecated. They now suggest you use annotations instead...

    @PersistJobDataAfterExecution
    @DisallowConcurrentExecution
    public class TestJob implements Job {
    

    This will explain what those annotations mean...

    The annotations cause behavior just as their names describe - multiple instances of the job will not be allowed to run concurrently (consider a case where a job has code in its execute() method that takes 34 seconds to run, but it is scheduled with a trigger that repeats every 30 seconds), and will have its JobDataMap contents re-persisted in the scheduler's JobStore after each execution. For the purposes of this example, only @PersistJobDataAfterExecution annotation is truly relevant, but it's always wise to use the @DisallowConcurrentExecution annotation with it, to prevent race-conditions on saved data.

提交回复
热议问题