一、试验代码
 //@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. BZOJ4268 : 小强的书架

    首先将所有高度乘上10,设f[i]为将前i本书放入书架的最小高度,则 \[\begin{eqnarray*}f[i]&=&\min(f[j-1]+first(j,i)+second(j ...

  2. Mac 10.13安装telnet

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

  3. Dynamic-Link Library Redirection

    Dynamic-Link Library Redirection Applications can depend on a specific version of a shared DLL and s ...

  4. 从零开始部署CAS服务器

    从0开始部署CAS服务器的操作过程文档,我已经整理完毕,一共分为8步,这8步都是我自己操作实践过的. Setp1:Ubuntu server安装 在virtual box中安装ubuntu serve ...

  5. btrace-dtrace-for-java-ish

    http://dtrace.org/blogs/ahl/2012/04/24/btrace-dtrace-for-java-ish/

  6. ASP.NET MVC下实现前端视图页的Session

    在ASP.NET MVC的控制器中可以实现Session处理.如果要在前端视图页实现Session该如何做呢?可以使用window.sessionStorage来做. AlexChittock用jQu ...

  7. ASP.NET MVC中实现属性和属性值的组合,即笛卡尔乘积02, 在界面实现

    在"ASP.NET MVC中实现属性和属性值的组合,即笛卡尔乘积01, 在控制台实现"中,在控制台应用程序中实现了属性值的笛卡尔乘积.本篇在界面中实现.需要实现的大致如下: 在界面 ...

  8. javascript 原型继承

    因为javascript没有专门的机制去实现类,所以这里只能是借助它的函数能够嵌套的机制来模拟实现类.在javascript中,一个函数,可以包含变量,也可以包含其它的函数,那么,这样子的话,我们就可 ...

  9. firedac连接linux的oracle

    firedac连接linux的oracle 首先要下载并安装 oci for linux.OCI的版本要和ORACLE数据库的版本一致. centos7环境下安装OCI:https://blog.cs ...

  10. Oracle Applications Documentation

    Oracle E-Business Suite Documentation Web Library Release 12.2+ Link Download Oracle E-Business Suit ...