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. Electron 应用入门 (参考官方示例)

    Electron 应用 1.去官方下案例 # 克隆示例项目的仓库 $ git clone https://github.com/electron/electron-quick-start # 进入这个 ...

  2. PHP7.27: connect mysql 5.7 using new mysqli_connect

    <!doctype html> <html> <head> <meta name="viewport" content="wid ...

  3. demo:动态生成专属二维码

    在日常生活中,随处可见二维码,那么js如何生成动态的专属二维码?其实,通过"二维码插件"我们可以快速生成二维码.在这,记录一下的生成专属二维码demo,一起来看看jquery.qr ...

  4. 【读书笔记】iOS-照相机与摄像头

    一,增强现实 增强现实(AR)是一种实时地计算摄影机影像的位置及角度并加上相应图像的技术,这种技术的目标是在屏幕上把虚拟世界套在现实世界并进行互动.这种技术估计由1990年提出.随着随身电子产品运算能 ...

  5. ArcGIS Server生成文件的权限问题处理

          [arcgisserver@gisserver3 usr]$ vi /arcgis/server/usr/init_user_param.sh          

  6. 【转】PHP 杂谈 坑爹的file_exists

    转自:http://www.cnblogs.com/baochuan/archive/2012/05/06/2445822.html 介绍   我发现了一个问题,今天与大家分享.我把整个过程描述一下. ...

  7. iOS开发NSDate、NSString、时间戳之间的转化

    //将UTCDate(世界标准时间)转化为当地时区的标准Date(钟表显示的时间) //NSDate *date = [NSDate date]; 2018-03-27 06:54:41 +0000 ...

  8. (网页)logback的使用和logback.xml详解(转)

    转自博客园:行走在云端的愚公: 一.logback的介绍 Logback是由log4j创始人设计的另一个开源日志组件,官方网站: http://logback.qos.ch.它当前分为下面下个模块: ...

  9. [20170825]11G备库启用DRCP连接3.txt

    [20170825]11G备库启用DRCP连接3.txt --//昨天测试了11G备库启用DRCP连接,要设置alter system set audit_trail=none scope=spfil ...

  10. 视频截图Util

    ​​ VideoToPicUtil.java package com.zhwy.util; import java.io.File; import java.util.ArrayList; impor ...