Skip to content
Advertisement

How to validate CronSequenceGenerator cron expressions?

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`

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement