import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class MyProcessor{

DateFormat sdf = new SimpleDateFormat("HH:mm:ss");

int[] delays = new int[]{8,3,6,2,2};
int index = 0;

@Scheduled(cron = "0/5 * * * * ?}")
public void process() {
try {
if(index > delays.length - 1){
if(index == delays.length){
System.out.println("---------- test end at " + sdf.format(new Date()) + " ---------");
}
index ++;
return;
}else{
System.out.println(index + ":start run at" + sdf.format(new Date()));
}
Thread.sleep(delays[index] * 1000);
System.out.println(index + ":end run at " + sdf.format(new Date()));
index ++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

转:http://blog.csdn.net/applebomb/article/details/52400154

Spring @Scheduled定时任务的fixedRate,fixedDelay,cron执行差异的更多相关文章

  1. Spring @Scheduled定时任务的fixedRate,fixedDelay,cron的作用和不同

    一.   三种定时类型. 1.cron  --@Scheduled(cron="0/5 * * * *?") 当时间达到设置的时间会触发事件.上面那个例子会每5秒执行一次. 201 ...

  2. Spring @Scheduled定时任务动态修改cron参数

    在定时任务类上增加@EnableScheduling注解,并实现SchedulingConfigurer接口.(注意低版本无效) 设置一个静态变量cron,用于存放任务执行周期参数. 另辟一线程,用于 ...

  3. Spring Scheduled定时任务报错 java.lang.IllegalStateException: Encountered invalid @Scheduled method 'xxx': For input string: "2S"

    报错信息如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ding ...

  4. spring注解@Scheduled中fixedDelay、fixedRate和cron表达式的区别

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  5. 使用轻量级Spring @Scheduled注解执行定时任务

    WEB项目中需要加入一个定时执行任务,可以使用Quartz来实现,由于项目就一个定时任务,所以想简单点,不用去配置那些Quartz的配置文件,所以就采用了Spring @Scheduled注解来实现了 ...

  6. 理解Spring定时任务的fixedRate和fixedDelay

    用过  Spring 的 @EnableScheduling 的都知道,我们用三种形式来部署计划任务,即 @Scheduled 注解的 fixedRate(fixedRateString), fixe ...

  7. 理解 Spring 定时任务的 fixedRate 和 fixedDelay 的区别

    用过 Spring 的 @EnableScheduling 的都知道,有三种方式,即 @Scheduled 注解的 fixedRate(fixedRateString), fixedDelay(fix ...

  8. Spring Boot 定时任务 @Scheduled

    项目开发中经常需要执行一些定时任务,比如在每天凌晨,需要从 implala 数据库拉取产品功能活跃数据,分析处理后存入到 MySQL 数据库中.类似这样的需求还有许多,那么怎么去实现定时任务呢,有以下 ...

  9. 【Spring】Spring的定时任务注解@Scheduled原来如此简单

    1 简介 定时任务的实现非常多,JDK的Timer.Spring提供的轻量级的Scheduled Task.QuartZ和Linux Cron等,还有一些分布式的任务调度框架.本文主要介绍Schedu ...

随机推荐

  1. idea not found for the web module

    intellij  IDEA  的tomcat 配置项里面没有的app web:war exploded  没有配置/路径

  2. HTML5本地存储localStorage与sessionStorage详解

    前言 在最近的项目中用到了html5的本地存储,下面总结一下. 1.html5几种存储形式 本地存储(localStorage && sessionStorage) 离线缓存(appl ...

  3. 图的遍历(bfs+dfs)模板

    bfs #include<iostream> #include<queue> #include<cstdio> using namespace std; queue ...

  4. 【工具相关】Web-Sublime Text2的用法(一)

    一,打开Sublime Text2--->出现如下所示界面. 二,在编辑区域可以随便输入数字.如图所示. 三,File--->Save. 四,将名字加上后缀,使其成为我们希望编辑的文件类型 ...

  5. CSS--居中方式总结

    一.水平居中方法 1.行内元素.字体的水平居中 1.对于行内元素(display值为inline或inline-block都可以)或者字体:父元素添加css规则:text-align:center; ...

  6. ActiveReports公开课开启报名,学习如何解决中国式复杂报表难题

    ActiveReports实战教学 90分钟解决中国式复杂报表六大需求 [开课时间]4月19日 [主讲老师]葡萄城资深报表专家 [培训方式]网络在线公开课 报名地址

  7. JMeter 配置元件之计数器Counter

    配置元件之计数器Counter   by:授客 QQ:1033553122 测试环境 apache-jmeter-2.13 1.   计数器简介 允许用户创建一个在线程组范围之内都可以被引用的计数器. ...

  8. (网页)textarea去掉回车换行

    转自CSDN: 1,把textarea内输入的内容中有回车换行的转成<br />传给后台, var content = $("#text").val().replace ...

  9. AspNetCore2身份验证

    1.在Startup类的Configure方法,添加身份验证的中间件AuthenticationMiddleware app.UseAuthentication(); 2.在Startup类的Conf ...

  10. java 基础one ---运算符and流程控制

    首先java这个了解下java的基础 首先java文件都是以.java结尾的  然后 他所有的内容都是有一个入口的就是放在了public static void main(String [] args ...