What corresponds to the Cron expression for fire for every X seconds, where X> 60?

I want my tasks to be performed every X seconds, there one to one corresponded to the task and X. Also, new tasks can be registered at runtime at their own intervals.

I tried to write a cron expression for such scenarios, but the documentation says that the value of seconds cannot be more than 59. Thus, the cron expression looks like this: "0/63 * * * *?" is invalid.

At first glance, the solution to this problem looked like this: "0/3 0/1 * * *?", But this means a completely different thing: run the task every three seconds of every minute.

Can you suggest what is the correct solution (cron expression) for this? I know I can use simple timers, but I have to use cron jobs using Quartz.

+3
source share
1 answer

The quartz cron syntax is for expressing time based on a standard 24-hour, 60-minute clock. It is not suitable for "every n seconds", where n can be any value. You cannot do this with cron expressions.

If you need to do this with quartz, you should use SimpleTrigger, not CronTrigger. You really don't have the option if you don't want to use the extremely complex collection of overlapping, artificially inferred cron expressions.

+6

Source: https://habr.com/ru/post/1748991/


All Articles