欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

What is corresponding Cron expression to fire in every X seconds, where X 60? --转载

发布时间:2025/4/5 编程问答 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 What is corresponding Cron expression to fire in every X seconds, where X 60? --转载 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

原文地址:http://stackoverflow.com/questions/2996280/what-is-corresponding-cron-expression-to-fire-in-every-x-seconds-where-x-60

Question:

I want my jobs to execute in every X seconds, there's one to one matching between job and X. Also during runtime there can be registered new jobs with their own intervals.

I've tried to write cron expression for such scenarios, but in documentation there's written that value of seconds can't be more than 59. So cron expression like this: "0/63 * * * * ?" isn't valid.

At first sight solution of that problem seemed to be expression like this: "0/3 0/1 * * * ?", but it means completely different thing: trigger job in every three second of every minute.

Can you suggest what is the right solution (cron expression) for that? I know I could use just simple timers, but I've to use cron jobs using Quartz.

 

answer:

The Quartz cron syntax is designed to express timing based on the standard 24 hour, 60 minute clock. It's not suitable for "every n seconds", where n can be any value. You're not going to able to do this with cron expressions.

If you need to do this with Quartz, you should use SimpleTrigger, not CronTrigger. You don't really have an option, unless you want to use a hugely complex collection of overlapping, artificially-deduced cron expressions.

 

碰到这个问题的时候,我陷入了误区,在stackoverflow上一看,明白自己掉坑里了。

转载于:https://www.cnblogs.com/davidwang456/p/4988431.html

总结

以上是生活随笔为你收集整理的What is corresponding Cron expression to fire in every X seconds, where X 60? --转载的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。