Spring @Scheduled 定时任务 周设置的坑

@Scheduled在spring-context包里。
具体位于org.springframework.scheduling.annotation.Scheduled
其cron字段的注释如下:

/**
 * A cron-like expression, extending the usual UN*X definition to include triggers
 * on the second as well as minute, hour, day of month, month and day of week.
 * <p>E.g. {@code "0 * * * * MON-FRI"} means once per minute on weekdays
 * (at the top of the minute - the 0th second).
 * <p>The special value {@link #CRON_DISABLED "-"} indicates a disabled cron trigger,
 * primarily meant for externally specified values resolved by a ${...} placeholder.
 * @return an expression that can be parsed to a cron schedule
 * @see org.springframework.scheduling.support.CronSequenceGenerator
 */
String cron() default "";

再看 org.springframework.scheduling.support.CronSequenceGenerator的注释:

/**
 * Date sequence generator for a
 * <a href="https://www.manpagez.com/man/5/crontab/">Crontab pattern</a>,
 * allowing clients to specify a pattern that the sequence matches.
 *
 * <p>The pattern is a list of six single space-separated fields: representing
 * second, minute, hour, day, month, weekday. Month and weekday names can be
 * given as the first three letters of the English names.
 *
 * <p>Example patterns:
 * <ul>
 * <li>"0 0 * * * *" = the top of every hour of every day.</li>
 * <li>"*&#47;10 * * * * *" = every ten seconds.</li>
 * <li>"0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.</li>
 * <li>"0 0 6,19 * * *" = 6:00 AM and 7:00 PM every day.</li>
 * <li>"0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day.</li>
 * <li>"0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays</li>
 * <li>"0 0 0 25 12 ?" = every Christmas Day at midnight</li>
 * </ul>
 *
 * @author Dave Syer
 * @author Juergen Hoeller
 * @author Ruslan Sibgatullin
 * @since 3.0
 * @see CronTrigger
 */
public class CronSequenceGenerator {
}

cron表达式的pattern需要查看 https://www.manpagez.com/man/5/crontab/

fieldallowed values
minute0-59
hour0-23
day of month1-31
month1-12 (or names, see below)
day of week0-7 (0 or 7 is Sun, or use names)

0和7是周日,那就是:

数字周几
0周日
1周一
2周二
3周三
4周四
5周五
6周六
7周日
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值