这些cron表达式是否等同?

编程入门 行业动态 更新时间:2024-10-28 15:26:59
本文介绍了这些cron表达式是否等同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

之间是否有任何差异

* / 5 * * * *< COMMAND>

0/5 * * * *< COMMAND>

解决方案<

  • 每隔5分钟执行一次, >
  • 第二个将在分钟0,5,10,... 55执行。

只有第一次在第5分钟执行第一次,他们将有相同的行为。

每5分钟可写成这样:

0,5,10,15,20,25,30,35,40,45 ,50,55 * * * *< COMMAND>

0/5 * * * *< COMMAND>

* / 5 * * * *< COMMAND>

无论如何,最后一个将开始任何时间的分钟变化,然后保持5分钟到下一个距离

$ / strong>。如果是单独的,它将意味着每分钟,每小时等。

/ 字符可用于指定值的增量。如果我们表示 X / Y ,则表示从第X分钟开始每隔Y分钟。

  • 0/15 = 每小时第15分钟,从分钟零开始 = 0,15,30,45
  • 3/20 = 每20分钟小时,从第三分钟开始 = 3,23,43
  • / 40 = 每小时的第40分钟 = 40
  • 3/40 = 每小时第40分钟,从第三分钟开始 = 43
  • $回到你的问题,两个运算符的使用得到以下结果:

    code> * / 5 =每5分钟开始一次。这样,每当更改分钟时,它将启动,并在5分钟,10等之后重复。

    0/5 =每5分钟从分钟0开始。它将在内部考虑为:0,5,10,15,20,25,30,35,40,45,50,55,因为这些是适合条件<

    有些参考资料:

    • CronTrigger
    • Linuxcrontab every示例

    Is there any diffenrence between

    */5 * * * * <COMMAND>

    and

    0/5 * * * * <COMMAND>

    ?

    解决方案

    It is not the same.

    • The first one will be executed every 5 minutes starting any moment, while
    • the second one will be executed on minutes 0, 5, 10,... 55.

    Only if the first one is executed on minute 5k for the first time, they will have the same behaviour.

    Every 5 minutes can be written like this:

    0,5,10,15,20,25,30,35,40,45,50,55 * * * * <COMMAND>

    this

    0/5 * * * * <COMMAND>

    or

    */5 * * * * <COMMAND>

    Anyway, last one will start any time the minute changes and then keep a distance of 5 minutes to next execution.

    The * character means every. If it is alone, it will mean every minute, every hour, etc.

    The / character can be used to specify increments to values. If we indicate X/Y it means every Y minutes starting at minute X.

    • 0/15 = every 15th minute of the hour, starting at minute zero = 0,15,30,45
    • 3/20 = every 20th minute of the hour, starting at minute three = 3,23,43
    • /40 = every 40th minute of the hour= 40
    • 3/40 = every 40th minute of the hour, starting at minute three= 43

    Coming back to your question, the use of both operators gets the following result:

    */5 = every 5 minutes starting anytime. This way, it will start whenever changes the minute and repeat after 5 minutes, 10, etc.

    0/5 = every 5 minutes starting on minute 0. It will be internally considered as: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55 as these are the minutes that suit the condition +5 minutes coming from start at minute 0.

    Some references:

    • CronTrigger
    • Linux "crontab every" examples

更多推荐

这些cron表达式是否等同?

本文发布于:2023-11-24 08:36:16,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   cron

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!