2

I have a cron Quartz trigger job executed each 30 seconds with this pattern:

0/30 * * * * ?

With this pattern, if my job spends more than 30 seconds to finish the execution, will next process be triggered and overlapped with first one?

Somewhere I've read that you can program a pattern to launch cron triggers n seconds after previous process finished, but can't find exact answer to program my jobs in this way.

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • I didn't work with quartz, but in spring "fixed-rate" and "cron" types could overlap and "fixed-delay" could not. Most likely Quartz works the same way. – AdamSkywalker Jun 18 '15 at 11:35
  • It isn't the cron that matters here, it is the trigger (or the job) if they allow to run jobs concurrently. – Tom Jun 18 '15 at 12:29
  • @Tom that's what I ask at the end of question and what you can see in answers here and in duplicated question... can't see the point of your comment... – Jordi Castilla Jun 18 '15 at 12:34

2 Answers2

1

What you might need here is stateful job implementation. You need to implement StatefulJob interface instead of Job

in the documentation it says

if a job is stateful, and a trigger attempts to 'fire' the job while it is already executing, the trigger will block (wait) until the previous execution completes.

You can find more details about it at this link http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/TutorialLesson03

Amit.rk3
  • 2,417
  • 2
  • 10
  • 16
1

StatefulJob could be the Job i need, but according to this and this answers, correct way to face this problem is:

Quartz 2

In version 2.0 of Quartz, StatefulJob is deprecated. It is now recommended to use annotations instead:

@DisallowConcurrentExecution
public class YourJob implements org.quartz.Job {
    void execute(JobExecutionContext context) {/*implementation omitted*/}
}

Explanation:

@DisallowConcurrentExecution: 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).

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109