一、试验代码
 //@Scheduled(fixedRate = 5000)
//@Scheduled(fixedDelay = 5000)
@Scheduled(cron ="*/5 * * * * *")
publicvoid reportCurrentTime()throwsInterruptedException{
log.info("action bgn {}----", dateFormat.format(newDate()));
Thread.sleep(1500);
log.info("action end {}", dateFormat.format(newDate()));
}
二、cron参数的配置
该参数非常灵活,这个参数的大致理解如下:
he 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.
Example patterns:
"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 * 6,19 * * *" = 6:00 AM and 7:00 PM 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   

 
有了这种配置之后,我就在想,我们以前做自动备份、自动导出的配置时,为什么要自己写这种逻辑,然后又要自己去定义配置格式呢,这是不是就叫做没文化真可怕
 
 
三、三种参数的试验数据如下。
fixedDelay=5000
2017-01-18 13:37:55.011     : action bgn 13:37:55----
2017-01-18 13:37:56.512     : action end 13:37:56
2017-01-18 13:38:01.513     : action bgn 13:38:01----
2017-01-18 13:38:03.013     : action end 13:38:03
2017-01-18 13:38:08.015     : action bgn 13:38:08----
2017-01-18 13:38:09.515     : action end 13:38:09
2017-01-18 13:38:14.517     : action bgn 13:38:14----
2017-01-18 13:38:16.018     : action end 13:38:16
 
 
fixedRate=5000
2017-01-18 13:39:23.643    : action bgn 13:39:23----
2017-01-18 13:39:25.144    : action end 13:39:25
2017-01-18 13:39:28.644    : action bgn 13:39:28----
2017-01-18 13:39:30.145    : action end 13:39:30
2017-01-18 13:39:33.643    : action bgn 13:39:33----
2017-01-18 13:39:35.144    : action end 13:39:35
2017-01-18 13:39:38.643    : action bgn 13:39:38----
2017-01-18 13:39:40.143    : action end 13:39:40
2017-01-18 13:39:43.643    : action bgn 13:39:43----
 
 
 
cron = "*/5 * * * * *"
2017-01-18 13:43:25.002     : action bgn 13:43:25----
2017-01-18 13:43:26.510     : action end 13:43:26
2017-01-18 13:43:30.001     : action bgn 13:43:30----
2017-01-18 13:43:31.502     : action end 13:43:31
2017-01-18 13:43:35.001     : action bgn 13:43:35----
2017-01-18 13:43:36.502     : action end 13:43:36
2017-01-18 13:43:40.001     : action bgn 13:43:40----
2017-01-18 13:43:41.502     : action end 13:43:41
2017-01-18 13:43:45.001     : action bgn 13:43:45----
2017-01-18 13:43:46.502     : action end 13:43:46

Spring系列:Scheduled注解学习笔记的更多相关文章

  1. #Spring实战第二章学习笔记————装配Bean

    Spring实战第二章学习笔记----装配Bean 创建应用对象之间协作关系的行为通常称为装配(wiring).这也是依赖注入(DI)的本质. Spring配置的可选方案 当描述bean如何被装配时, ...

  2. Spring 的@Scheduled注解实现定时任务运行和调度

    Spring 的@Scheduled注解实现定时任务运行和调度 首先要配置我们的spring.xml   ---  即spring的主配置文件(有的项目中叫做applicationContext.xm ...

  3. Spring实战第八章学习笔记————使用Spring Web Flow

    Spring实战第八章学习笔记----使用Spring Web Flow Spring Web Flow是一个Web框架,它适用于元素按规定流程运行的程序. 其实我们可以使用任何WEB框架写流程化的应 ...

  4. Spring实战第一章学习笔记

    Spring实战第一章学习笔记 Java开发的简化 为了降低Java开发的复杂性,Spring采取了以下四种策略: 基于POJO的轻量级和最小侵入性编程: 通过依赖注入和面向接口实现松耦合: 基于切面 ...

  5. Spring Cloud微服务学习笔记

    Spring Cloud微服务学习笔记 SOA->Dubbo 微服务架构->Spring Cloud提供了一个一站式的微服务解决方案 第一部分 微服务架构 1 互联网应用架构发展 那些迫使 ...

  6. spring mvc 注解 学习笔记(一)

    以前接触过spring,但是没有接触spring mvc 以及注解的应用,特习之,记之: 注解了解 @Component 是通用标注, @Controller 标注web控制器, @Service 标 ...

  7. Spring 注解学习笔记

    声明Bean的注解: @Component : 组件,没有明确的角色 @Service : 在业务逻辑层(service层)使用 @Repository : 在数据访问层(dao层)使用. @Cont ...

  8. Spring定时任务@Scheduled注解使用方式

    1.开篇 spring的@Scheduled定时任务相信大家都是十分熟悉.最近在使用过程中发现了一些问题,写篇文章,和大家分享一下.结论在最后,不想看冗长过程的小伙伴可以直接拉到最后看结论. 2.简单 ...

  9. Spring注解学习笔记一

    一.Retention注解Retention(保留)注解说明,这种类型的注解会被保留到那个阶段. 有三个值: 1.RetentionPolicy.SOURCE —— 这种类型的Annotations只 ...

随机推荐

  1. Activemq+Zookeeper集群

    如果在同一台机器上请参考 http://blog.csdn.net/liuyifeng1920/article/details/50233067 http://blog.csdn.net/zuolj/ ...

  2. Elasticsearch 实现自定义排序插件

    插件入口: package ttd.ugc.plugin; import org.elasticsearch.plugins.Plugin;import org.elasticsearch.scrip ...

  3. input文字颜色、光标颜色

    <input type="text" placeholder="输入框"> input{ color: red;/*输入文字.光标颜色*/ -web ...

  4. centos上安装elasticsearch 5.5.1 遇到的各种坑

    mac玩得好好滴,一次性启动成功,结果在centos上安装时,遇坑无数,记录一下: 一.只能localhost访问的问题修改 conf\elasticsearch.yml network.host: ...

  5. Google Reader明日关闭:14款替代品对比

    北京时间6月30日上午消息,谷歌将于7月1日关闭RSS阅读器服务Google Reader,目前许多用户已转向其他的RSS阅读器服务. 美国科技博客Marketing Land本周对市面上多个RSS阅 ...

  6. Android开发之解决APP启动白屏或者黑屏闪现的问题

    在做搜芽的过程中,发现那个外包人缘做的不行,由于启动的时候会停顿,然后白屏一会,联想到几个月前我在我的三僚企业通信软件里面拉起9K-Mail的时候也会黑屏,所以决定学习一下.解决一下.这不,万能的网络 ...

  7. stap 命令

    SystemTap accepts script as command line option or external file, for example: * Command-line script ...

  8. Android笔记之 网络http通信

    0.在认识HTTP前先认识URL 在我们认识HTTP之前,有必要先弄清楚URL的组成,比如: http://www.******.com/china/index.htm 它的含义例如以下: 1. ht ...

  9. 自定义两行可左右滑动的GridView

    效果图: xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  10. 对一个前端使用AngularJS后端使用ASP.NET Web API项目的理解(1)

    chsakell分享了一个前端使用AngularJS,后端使用ASP.NET Web API的项目. 源码: https://github.com/chsakell/spa-webapi-angula ...