Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate CronSequenceGenerator cron expressions?

Tags:

java

spring

cron

How could I validate cron expressions that are prepared for use of CronSequenceGenerator?

I mean, I cannot wait until the cron executes automatically as I'm defining like monthly intervals.

Is the following correct? How can I be sure?

monthly at midnight: `0 0 0 1 * *`
monthly at 1 am: `0 0 1 1 * *`
weekly, on sunday at midnight: `0 0 0 * * SUN`
like image 387
membersound Avatar asked Jan 20 '16 14:01

membersound


People also ask

What does question mark mean in cron?

A question mark ( ? ) is allowed in the day-of-month and day-of-week fields. It is used to specify “no specific value,” which is useful when you need to specify something in one of these two fields, but not in the other.


2 Answers

The Spring's CronSequenceGenerator class has a method isValidExpression(String expression) which takes the cron expression and returns a boolean.

like image 82
batristio Avatar answered Sep 29 '22 07:09

batristio


I guess if you are ok with quartz api then you should use org.quartz.CronExpression.isValidExpression(String s)

Api ref http://quartz-scheduler.org/api/2.2.0/org/quartz/CronExpression.html

like image 43
Pankaj Pandey Avatar answered Sep 29 '22 08:09

Pankaj Pandey