一、试验代码
 //@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. 处理javabean的JSP标签

    (1) 关于javabean要求: 1,具有无参的构造函数. 2,针对每一个成员变量,因改提供相应get/set. 3,implments Serializable(实现才能对象序列化). (2) 使 ...

  2. python中关于if-else使用性能的一点感悟

    今天做leetcode第7题关于数字倒序的问题,分别使用如下程序:(72ms) class Solution: def reverse(self, x): """ :ty ...

  3. POJ3070 Fibonacci[矩阵乘法]【学习笔记】

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Descri ...

  4. GEEK-2018之隐藏在混乱之中的绝密情报 writeup

    题目如上 打开题目后发现,提示robots 随后提示又需要改一改名字 修改文件名为humans.txt之后发现 有个备份文件,直接访问www.zip就可以下载了 下载打开后如下: 在其中看到了unse ...

  5. NOIP练习赛题目3

    魔兽争霸 难度级别:C: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 小x正在销魂地玩魔兽他正控制着死亡骑士和n个食尸鬼(编号1-n)去打 ...

  6. TreeMap(红黑树)源码分析

    1. HashMap.Entry(红黑树节点) private static final boolean RED = false; private static final boolean BLACK ...

  7. 20172319 实验四 《Android程序设计》实验报告

    20172319 2018.05.17-30 实验四<Android程序设计> 实验报告 课程名称:<程序设计与数据结构> 学生班级:1723班 学生姓名:唐才铭 学生学号:2 ...

  8. UVALive 6908 Electric Bike dp

    Electric Bike 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8 ...

  9. LPC18xx/43xx SWD/JTAG Debug Connector

  10. Processing an OS Descriptor request -- Remote Desktop Protocol

    Special processing on the client is needed when processing TS_URB_OS_FEATURE_DESCRIPTOR_REQUEST. The ...