springboot成神之——Scheduler定时任务
本文介绍spring的Scheduler定时任务
目录结构

config
// @EnableScheduling 开启后台任务
package com.springlearn.learn.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
@Configuration
@EnableScheduling
public class SchedulerConfig {
}
scheduler
// 获取当前时间
package com.springlearn.learn.scheduler;
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 GetCurrentTimeSchedule {
private static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss sss");
@Scheduled(initialDelay=3*1000, fixedDelay=1*1000)
public void GetCurrentTime() {
Date now = new Date();
System.out.println("Now is:" + df.format(now));
}
}
@Scheduled配置参数
cron
second, minute, hour, day of month, month, day(s) of week
@Scheduled(cron="0 * * * * *" ) 每分钟执行一次
@Scheduled(cron="*/10 * * * * *") 每10秒执行一次
@Scheduled(cron="*0 0 8-10 * * *") 8点,9点,10点各执行一次
@Scheduled(cron="0 0/30 8-10 * * *") 8点,8点半,9点,9点半,10点,10点半各执行一次
@Scheduled(cron="0 0 9-17 * * MON-FRI") 周一到周五的每天的9点到17点各执行一次
@Scheduled(cron="0 0 0 1 1 ?") 元旦节午夜执行一次
zone
时区
@Scheduled(cron="0 * * * * *", zone="Asia/Shanghai")
fixedDelay
当上一个任务完成,才会执行下一个
fixedDelayString
fixedRate
不管上一个任务完没完成,时间一到,都会执行下一个
fixedRateString
initialDelay
initialDelayString
springboot成神之——Scheduler定时任务的更多相关文章
- springboot成神之——ioc容器(依赖注入)
springboot成神之--ioc容器(依赖注入) spring的ioc功能 文件目录结构 lang Chinese English GreetingService MyRepository MyC ...
- springboot成神之——springboot入门使用
springboot创建webservice访问mysql(使用maven) 安装 起步 spring常用命令 spring常见注释 springboot入门级使用 配置你的pom.xml文件 配置文 ...
- springboot成神之——mybatis和mybatis-generator
项目结构 依赖 generator配置文件 properties配置 生成文件 使用Example 本文讲解如何在spring-boot中使用mybatis和mybatis-generator自动生成 ...
- springboot成神之——swagger文档自动生成工具
本文讲解如何在spring-boot中使用swagger文档自动生成工具 目录结构 说明 依赖 SwaggerConfig 开启api界面 JSR 303注释信息 Swagger核心注释 User T ...
- springboot成神之——log4j2的使用
本文介绍如何在spring-boot中使用log4j2 说明 依赖 日志记录语句 log4j2配置文件 本文介绍如何在spring-boot中使用log4j2 说明 log4j2本身使用是非常简单的, ...
- springboot成神之——mybatis在spring-boot中使用的几种方式
本文介绍mybatis在spring-boot中使用的几种方式 项目结构 依赖 WebConfig DemoApplication 方式一--@Select User DemoApplication ...
- springboot成神之——application.properties所有可用属性
application.properties所有可用属性 # =================================================================== # ...
- springboot成神之——springboot+mybatis+mysql搭建项目简明demo
springboot+mybatis+mysql搭建项目简明demo 项目所需目录结构 pom.xml文件配置 application.properties文件配置 MyApplication.jav ...
- springboot成神之——websocket发送和请求消息
本文介绍如何使用websocket发送和请求消息 项目目录 依赖 DemoApplication MessageModel WebConfig WebSocketConfig HttpHandshak ...
随机推荐
- 7zip 自解压安装程序
包含自解压安装器的包https://jaist.dl.sourceforge.net/project/sevenzip/7-Zip/9.20/7z920_extra.7z详细说明见7-zip帮助文档的 ...
- 27-THREE.JS 平面
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...
- 转一篇pgpool配置
转一篇pgpool配置 http://dz.sdut.edu.cn/blog/subaochen/2013/08/postgresql-9-1的failover配置及其管理/ 环境介绍 在两台虚拟机上 ...
- css3: scrollLeft,scrollWidth,clientWidth,offsetWidth 的区别
(需要提一下:CSS中的margin属性,与clientWidth.offsetWidth.clientHeight.offsetHeight均无关) offsetwidth:是元素相对父元素的偏移宽 ...
- Angular提示文件不是一个有效的模块
ERROR in src/app/app.component.ts(2,23): error TS2306: File '/home/jerry/angular/todo/src/app/model. ...
- <tf-idf + 余弦相似度> 计算文章的相似度
背景知识: (1)tf-idf 按照词TF-IDF值来衡量该词在该文档中的重要性的指导思想:如果某个词比较少见,但是它在这篇文章中多次出现,那么它很可能就反映了这篇文章的特性,正是我们所需要的关键词. ...
- Adobe Fireworks CS6是一款集网页图片设计、制作与编辑为一体的专业软件
Adobe Fireworks CS6是一款集网页图片设计.制作与编辑为一体的专业软件,它不仅可以轻松制作出各种动感的Gif.动态按钮.动态翻转等网络图片,还可以轻松实现大图切割,让网页加载的图片显示 ...
- 【java规则引擎】drools6.5.0版本中kmodule.xml解析
kmodule.xml文件存放在src/main/resources/META-INF/文件夹下. <?xml version="1.0" encoding="UT ...
- LOJ2823 「BalticOI 2014 Day 1」三个朋友
题意 给定一个字符串 S,先将字符串 S 复制一次(变成双倍快乐),得到字符串 T,然后在 T 中插入一个字符,得到字符串 U. 给出字符串 U,重新构造出字符串 S. 所有字符串只包含大写英文字母. ...
- php执行多个存储过程(二)
使用公共连接文件形式 include_once 'inc/conni.php'; $result = mysqli_query($conni, "call proc_test()" ...