Ensure that Spring Quartz job execution doesn't overlap

后端 未结 7 1411
迷失自我
迷失自我 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:34

    I'm not sure you want synchronisation, since the second task will block until the first finishes, and you'll end up with a backlog. You could put the jobs in a queue, but from your description it sounds like the queue may grow indefinitely.

    I would investigate ReadWriteLocks, and let your task set a lock whilst it is running. Future tasks can inspect this lock, and exit immediately if an old task is still running. I've found from experience that that's the most reliable way to approach this.

    Perhaps generate a warning as well so you know you're encountering problems and increase the time interval accordingly ?

提交回复
热议问题