一、试验代码
 //@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. springmvc学习总结(一) -- 从零搭建,基础入门

    1.新建maven项目 参考mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上)第一部分,修改配置 2.修改pom.xml 文件 <proj ...

  2. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem I. Alien Rectangles 数学

    Problem I. Alien Rectangles 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c ...

  3. inline关键字的作用

    一.在C&C++中,inline关键字用来定义一个类的内联函数,引入它的主要原因是用它替代C中表达式形式的宏定义. 如下面一宏定义表达式: #define express(v1,v2) (v1 ...

  4. MikroTik RouterOS网址资源收集

    routeros|mikrotik|ros|软路由论坛|中国路由网|软件路由|软件路由器|routeros技术论坛|路由论坛 - Powered by Discuz!   Mikrotik RB450 ...

  5. Mac 10.13安装telnet

    狗日的Mac 10.13默认不自带telnet!!!苹果你以为你的操作系统真的那么平民吗,别做梦,用你只不过是为了开发!!! 安装: brew install telnet 如果你用上述方法安装不上, ...

  6. hdu4467 Graph

    Graph Problem Description P. T. Tigris is a student currently studying graph theory. One day, when h ...

  7. Programming 2D Games 读书笔记(第二章)

      本意还是想了解DirectX的,由于网上拿不到书的pdf文档,幸好有作者的源代码示例,想完整的看一下,基本的游戏需要的点. 下面直接以代码为例,仅用于帮助自身理解 http://www.progr ...

  8. AutoMapper在MVC中的运用小结

    配置.单元测试.AOP注入 Decimal转换成String类型 源数组转换成目标数组 源中的集合(数组)属性转换成目标中的集合(数组)属性 子类父类间的映射 源字典集合转换成目标字典集合 枚举映射 ...

  9. lufylegend:图片的加载和显示

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <script ...

  10. ibatis.net:第四天,Update 和 Delete

    xml <update id="UpdateOrder" parameterClass="Order"> UPDATE [Orders] SET C ...