Spring @Scheduled定时任务的fixedRate,fixedDelay,cron执行差异

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执行差异的更多相关文章
- Spring @Scheduled定时任务的fixedRate,fixedDelay,cron的作用和不同
一. 三种定时类型. 1.cron --@Scheduled(cron="0/5 * * * *?") 当时间达到设置的时间会触发事件.上面那个例子会每5秒执行一次. 201 ...
- Spring @Scheduled定时任务动态修改cron参数
在定时任务类上增加@EnableScheduling注解,并实现SchedulingConfigurer接口.(注意低版本无效) 设置一个静态变量cron,用于存放任务执行周期参数. 另辟一线程,用于 ...
- 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 ...
- spring注解@Scheduled中fixedDelay、fixedRate和cron表达式的区别
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 使用轻量级Spring @Scheduled注解执行定时任务
WEB项目中需要加入一个定时执行任务,可以使用Quartz来实现,由于项目就一个定时任务,所以想简单点,不用去配置那些Quartz的配置文件,所以就采用了Spring @Scheduled注解来实现了 ...
- 理解Spring定时任务的fixedRate和fixedDelay
用过 Spring 的 @EnableScheduling 的都知道,我们用三种形式来部署计划任务,即 @Scheduled 注解的 fixedRate(fixedRateString), fixe ...
- 理解 Spring 定时任务的 fixedRate 和 fixedDelay 的区别
用过 Spring 的 @EnableScheduling 的都知道,有三种方式,即 @Scheduled 注解的 fixedRate(fixedRateString), fixedDelay(fix ...
- Spring Boot 定时任务 @Scheduled
项目开发中经常需要执行一些定时任务,比如在每天凌晨,需要从 implala 数据库拉取产品功能活跃数据,分析处理后存入到 MySQL 数据库中.类似这样的需求还有许多,那么怎么去实现定时任务呢,有以下 ...
- 【Spring】Spring的定时任务注解@Scheduled原来如此简单
1 简介 定时任务的实现非常多,JDK的Timer.Spring提供的轻量级的Scheduled Task.QuartZ和Linux Cron等,还有一些分布式的任务调度框架.本文主要介绍Schedu ...
随机推荐
- CTO 之“六脉神剑”
他深谙电商之道,从零打造 1 号店网站及供应链系统,以技术引领业务发展.他是欧电云创始人韩军,下面将由他分享完美 CTO “六脉神剑”的经验之谈. 首先,从对 CTO 的一个认识误区讲起. 不写代码的 ...
- ORM&MySQL
概念: ORM:对象关系映射 , 全拼 Object-Relation Mapping ,是一种为了解决面向对象与关系数据库存在的互不匹配现象的技术.主要实现模型对象到关系型数据库数据的映射.比如:把 ...
- Android项目实战(三十二):圆角对话框Dialog
前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话框的"确定"按钮 难点:1.对话框边框圆角 ...
- Android 2018最新验证手机号正则表达式
/** * 判断字符串是否符合手机号码格式 * 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,18 ...
- Storm的DRPC
RPC:Remote Procedure Call DRPC:Distributed RPC Hadoop提供了RPC的实现机制,实现方法见:<>,本文主要介绍Storm的DRPC. ...
- (网页)javascript小技巧(非常全)
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcE ...
- [20170728]oracle保留字.txt
[20170728]oracle保留字.txt --//oracle有许多保留字,我印象最深的就是使用rman备份表空间test,test就是rman里面的保留字.--//还有rman也是rman里面 ...
- 线程:生命周期、实现方式、start()和run()的区别!
1.线程的生命周期 要想实现多线程,必须在主线程中创建新的线程对象.Java语言使用Thread类及其子类的对象来表示线程,在它的 一个完整的生命周期中通常要经历如下的五种状态: 新建:当一个Thre ...
- element-ui的回调函数Events的用法
做轮播的时候想用这个change回调函数,但是官方文档上竟然就只列了这么一行东西,完全没有示例代码(也可能我没找到哈) 鼓捣了半天,东拼西凑终于找到了靠谱的使用方法,其实很简单 在轮播组件上加上@ch ...
- 4.4Python数据类型(4)之字符串函数
返回总目录 目录: 1.字符串的查找计算 2.字符串的转换 3.字符串的填充压缩 4.字符串的分割拼接 5.字符串的判定 (一)字符串的查找计算 (1)len(str)计算字符串的总数 (2)find ...