Jun
Jun

Reputation: 570

Java quartz scheduler: convert unix cron format to quartz cron format

I want to check if given DateTime matches unix cron format or not. I was trying to use Quartz, but Quartz doesn't support "Day of Month" and "Day of Week" are both "*".

For example:

0 * * * * * (which means run every minutes) is not supported in Quartz

because it must be

0 * * * * ? or 0 * * ? * *. 

Can someone tell me why and also tell me how can I match a given DateTime to Unix cron format?

Thanks

Upvotes: 5

Views: 3809

Answers (1)

matt
matt

Reputation: 76

Why the cron syntax is different is not a question I can answer, but if all you're looking for is a means to convert from unix to quartz syntax, https://github.com/jmrozanec/cron-utils has helped me in the past.

As far as I know, matching a given date time to a cron syntax is not exactly a simple task, because cron implies a certain frequency of repetition, where as a date/time is a moment in time.

If you're trying to schedule a job to execute once, I suggest using a simple trigger.

If you really want a cron job that executes on some schedule, the above cron-utils library, combined with a cron trigger should do the trick.

Implementations of both triggers (and more) can be found here: http://www.quartz-scheduler.org/api/2.2.1/index.html

Upvotes: 6

Related Questions