码迷,mamicode.com
首页 > 编程语言 > 详细

spring @Scheduled用法

时间:2015-12-14 14:06:57      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:

@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

spring @Scheduled用法

标签:

原文地址:http://www.cnblogs.com/majia1949/p/5044919.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!