Quartz Cron Trigger which fires a job for every 40 seconds

1.6k Views Asked by At

I faced a weird situation, where I have an only option to use Cron trigger and need to trigger a job for every 40 seconds. Is this possible with Cron trigger. If yes, can you please help.

My expression could go like below:

0/40 * * * * ?

actual result:

  • job executed at 12:00:00
  • job executed at 12:00:40
  • job executed at 12:01:00
  • job executed at 12:01:40

expected result:

  • job executed at 12:00:00
  • job executed at 12:00:40
  • job executed at 12:01:20
  • job executed at 12:02:00

Thanks in advance...

1

There are 1 best solutions below

2
sozkul On

in quartz configuration xml file, set <cron-expression> of job definition like below;

<cron-expression>0/40 * * * * ?</cron-expression>

Also, keep in mind that every 40 seconds works like;

fire on 10:00:40
fire on 10:01:20
fire on 10:02:00
...