spring @Scheduled用法
2015-12-14 12:59
330 查看
@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[/code]
参考
http://stackoverflow.com/questions/26147044/spring-cron-expression-for-every-day-101am
相关文章推荐
- java读书笔记-java提高篇(2)
- spring框架(一)
- java获取当前时间后,经SimpleDateFormat格式化成String类型,差8小时
- java——关于异常处理机制的简单原理和应用
- Java实时监控日志文件并输出
- myeclipse 打不开struts.xml文件
- Struts1和Struts2的区别和对比(完整版)
- JAVA-堆区,栈区,方法区。
- Spring BeanPostProcessor与动态加载数据源配置
- 彻底理解JAVA动态代理
- JAVA NIO原理图文分析及代码实现
- Spring深入学习:jar包详解
- JAVA反射系列之Field,java.lang.reflect.Field使用获取方法
- JAVA设计模式之:单例模式
- 图学java基础篇之集合
- Eclipse安装FindBugs,并进行静态代码扫描
- java格式化数字DecimalFormat
- MyEclipse设置默认的目光格式
- eclipse下svn切换地址
- Java魔法堂:String.format详解