简体   繁体   English

Java Crystal Scheduler:将UNIX cron格式转换为石英cron格式

[英]Java quartz scheduler: convert unix cron format to quartz cron format

I want to check if given DateTime matches unix cron format or not. 我想检查给定的DateTime是否与unix cron格式匹配。 I was trying to use Quartz, but Quartz doesn't support "Day of Month" and "Day of Week" are both "*". 我试图使用Quartz,但是Quartz不支持“月日”和“星期几”均为“ *”。

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? 有人可以告诉我原因,还可以告诉我如何将给定的DateTime与Unix cron格式匹配吗?

Thanks 谢谢

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. 为什么 cron语法与众不同,这不是我可以回答的问题,但是如果您要寻找的只是将unix转换为石英语法的一种方法, https://github.com/jmrozanec/cron-utils帮助了我过去。

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. 据我所知,将给定的日期时间与cron语法进行匹配并不是一件容易的事,因为cron意味着一定的重复频率,而日期/时间就是时刻。

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. 如果您确实想要按计划执行的cron作业,则上面的cron-utils库与cron触发器结合可以解决问题。

Implementations of both triggers (and more) can be found here: http://www.quartz-scheduler.org/api/2.2.1/index.html 这两个触发器(以及更多触发器)的实现都可以在这里找到: http : //www.quartz-scheduler.org/api/2.2.1/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM