cron expression for every 30 seconds in quartz scheduler?
Asked Answered
B

4

27

I am using Quartz Scheduler to run my jobs. I want to run my job every thirty seconds. What will be my cron expression for that?

For every one minute, I am using below cron expression:

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

What it will be for every thirty seconds?

Bumptious answered 5/2, 2016 at 0:13 Comment(0)
L
34

The first element represents the seconds; to run at second 0 and 30 use the following:

<cron-expression>0/30 0/1 * 1/1 * ? *</cron-expression>
Lezlielg answered 5/2, 2016 at 0:22 Comment(4)
Thanks Ian. One more thing what will be the cron expression to run every 15 minutes but for the first time it should run immediately? And then afterwards every 15 minutes? Does this looks right 0 0/15 * 1/1 * ? *?Bumptious
That is the correct cron expression for every 15 minutes. Cron is a rigid structure, and doesn't conform well what you are asking (now, now+15min, etc). That cron will run at minute, 0, 15, 30, 45 ..Lezlielg
Maybe you need Triggers, not cronLezlielg
If you're using spring [spring-boot] make sure to omit last * , otherwise it will throw an error saying can't accept fields other than six.Bussey
N
13

I hope this answer will help you. Please define the cron expression the below

 0/30 * * * * ? *

And then you go this website and test Cron Expression Generator & Explainer - Quartz.

Nagel answered 28/8, 2019 at 3:55 Comment(0)
L
11

The same effect we can reach (Quartz Spring) using simpler construction:

0/30 * * * * ? *

The last asterisk we can omit.

0/30 * * * * ?

Quartz scheduler cron trigger documentation 2.x

Latoyalatoye answered 17/9, 2018 at 21:50 Comment(0)
A
0

If you are using Spring framework, make use of @PostConstruct annotation and then @Scheduled(cron=0 0/15 * 1/1 * ?) to trigger now, now+15min and so on.

Aggie answered 21/9, 2017 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.