FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");

fdf.format(new Date())
import java.util.Date;

import org.apache.commons.lang3.time.FastDateFormat;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import com.dudu.constant.Constant; @Component
public class ScheduleJobs { public final static long SECOND = 1 * 1000;
FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); /**
* 固定等待时间 @Scheduled(fixedDelay = 时间间隔 )
* @throws InterruptedException
*/
@Scheduled(fixedDelay = SECOND * 2)
public void fixedDelayJob() throws InterruptedException {
Constant.LOGGER.info("[FixedDelayJob Execute]"+fdf.format(new Date()));
} /**
* 固定间隔时间 @Scheduled(fixedRate = 时间间隔 )
*/
@Scheduled(fixedRate = SECOND * 4)
public void fixedRateJob() {
Constant.LOGGER.info("[FixedRateJob Execute]"+fdf.format(new Date()));
} /**
* Corn表达式 @Scheduled(cron = Corn表达式)
*/
@Scheduled(cron = "0/4 * * * * ?")
public void cronJob() {
Constant.LOGGER.info("[CronJob Execute]"+fdf.format(new Date()));
} }

SpringBoot定时任务(Spring Schedule )实现方法的更多相关文章

  1. SpringBoot系列:Spring Boot定时任务Spring Schedule

    Spring Schedule是Spring提供的定时任务框架,相较于Quartz,Schedule更加简单易用,在中小型应用中,对于大部分需求,Schedule都可以胜任. 一.Spring Sch ...

  2. SpringBoot系列: Spring MVC视图方法的补充

    SpringMVC 视图方法的参数, 已经在这个文章中写得非常清楚了, 链接为 https://www.cnblogs.com/morethink/p/8028664.html 这篇文章做一些补充. ...

  3. SpringBoot定时任务 - Spring自带的定时任务是如何实现的?有何注意点?

    通过前文我们基本梳理了定时任务体系:Timer和ScheduledExecutorService是JDK内置的定时任务方案,以及Netty内部基于时间轮实现的HashedWheelTimer,再到Qu ...

  4. SpringBoot之旅 -- 定时任务两种(Spring Schedule 与 Quartz 整合 )实现

    相关文章 Spring Boot 相关文章目录 前言 最近在项目中使用到定时任务,之前一直都是使用Quartz 来实现,最近看Spring 基础发现其实Spring 提供 Spring Schedul ...

  5. Spring Schedule 实现定时任务

    很多时候我们都需要为系统建立一个定时任务来帮我们做一些事情,SpringBoot 已经帮我们实现好了一个,我们只需要直接使用即可,当然你也可以不用 SpringBoot 自带的定时任务,整合 Quar ...

  6. spring schedule定时任务(一):注解的方式

    我所知道的java定时任务的几种常用方式: 1.spring schedule注解的方式: 2.spring schedule配置文件的方式: 3.java类继承TimerTask: 第一种方式的实现 ...

  7. 小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解

    笔记 1.SpringBoot定时任务schedule讲解     简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类            ...

  8. Spring自带的定时任务框架Schedule的优缺点及使用

    spring自带的定时任务框架的有点:简单,拆箱即用 spring自带的定时任务框架的缺点: 不支持集群:为避免重复执行的问题 不支持生命周期统一管理:不重启服务情况下关闭,启动任务 不支持分片任务: ...

  9. Spring boot(三) springboot 定时任务

    这个不多说,springboot 定时任务非常简单就可以实现了. 30s运行一次 , @Scheduled(cron="0,30 * * * * ?") 通过这个控制定时时间 cr ...

随机推荐

  1. bzoj3790 manacher算法+贪心

    紧跟jk大佬的步伐 这道题哇 因为机器一能生成回文串 所以我们只要用manacher跑一遍求出q[i]这样就把问题转化成了类似线段覆盖的题目 贪心就好了 至于,BIT优化dp我不会所以直接贪心了 注意 ...

  2. DotNETCore 学习笔记 依赖注入和多环境

    Dependency Injection ------------------------------------------------------------------------ ASP.NE ...

  3. mysql分页查询语法

    一.limit语法 SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset LIMIT 子句可以被用于强制 SELECT 语句返回指 ...

  4. javascript 将字符串当函数执行

    //语法 eval(str); //demo var t = "func"; eval(''+func+'()');

  5. 解决:org.apache.tomcat.jni.Error: 70023: This function has not been implemented on this platform

    centos7.3 启动tomcat 出现错误: 八月 08, 2017 4:58:47 下午 org.apache.catalina.core.StandardEngine startInterna ...

  6. Selenium2+python自动化74-jquery定位【转载】

    转至博客:上海-悠悠 前言 元素定位可以说是学自动化的小伙伴遇到的一道门槛,学会了定位也就打通了任督二脉,前面分享过selenium的18般武艺,再加上五种js的定位大法. 这些还不够的话,今天再分享 ...

  7. Selenium2+python自动化-窗口多标签处理方法总结(转载)

    本篇转自博客:上海-小T 原文地址:https://i.cnblogs.com/EditArticles.aspx?opt=1 我们在用Selenium遇到多个浏览器窗口或单个浏览器多个标签(Tab) ...

  8. Linux命令之:tr

    1. 用途: tr,translate的简写,主要用于压缩重复字符,删除文件中的控制字符以及进行字符转换操作. 2. 语法: tr [OPTION]... SET1 [SET2] 3. 参数: -s: ...

  9. 《锋利的JQuery》读书要点笔记3——事件和动画

    第四章 jQuery中的事件和动画 JS和HTML的交互是通过用户和浏览器操作页面时引发的事件来处理的,事件由浏览器自动生成. 4.1 jQuery中的事件 1. 加载DOM 这里主要是搞明白wind ...

  10. hdu 5174(计数)

    Ferries Wheel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...