spring @Scheduled用法

@Scheduled(cron = "0 5 * * * ?")
org.springframework.scheduling.annotation.Scheduled

/**
 * Annotation that marks a method to be scheduled. Exactly one of the
 * <code>cron</code>, <code>fixedDelay</code>, or <code>fixedRate</code>
 * attributes must be provided.
 *
 * <p>The annotated method must expect no arguments and have a
 * <code>void</code> return type.
 *
 * <p>Processing of {@code @Scheduled} annotations is performed by
 * registering a {@link ScheduledAnnotationBeanPostProcessor}. This can be
 * done manually or, more conveniently, through the {@code <task:annotation-driven/>}
 * element or @{@link EnableScheduling} annotation.
 *

 

Try with:

@Scheduled(cron = "0 1 1 * * ?")
Here you are some example pattern found on spring forum:

* "0 0 * * * *" = the top of every hour of every day.
* "*/10 * * * * *" = every ten seconds.
* "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
* "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
* "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
* "0 0 0 25 12 ?" = every Christmas Day at midnight
Cron expression is represented by six fields:

second, minute, hour, day of month, month, day(s) of week
(*) means match any

*/X means "every X"

? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field.

PS: in order to make it works, remember to enable it in your application context: http://docs.spring.io/autorepo/docs/spring-framework/current/spring-framework-reference/html/scheduling.html#scheduling-annotation-support

 

 

参考

http://stackoverflow.com/questions/26147044/spring-cron-expression-for-every-day-101am

转载于:https://www.cnblogs.com/majia1949/p/5044919.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值