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 ...
随机推荐
- MSSQL旋转和反旋转的例子
1.旋转 ;WITH CTE AS ( AS VAL UNION ALL UNION ALL UNION ALL UNION ALL UNION ALL UNION ALL UNION ALL ) S ...
- 蓝牙(cc2540) 协议栈 学习一
---------------------------------------------------------- app ------------------------------------- ...
- S5PV210启动过程详解1
内存: SRAM 静态内存 特点就是容量小.价格高.优点是不需要软件初始化直接上电就能用 DRAM 动态内存 特点就是容量大.价格低.缺点就是上电后不能直接使用,需要软件初始化后才可 ...
- aac adts & LATM封装码流分析
本文继续上一篇文章的内容,介绍一个音频码流处理程序.音频码流在视频播放器中的位置如下所示. 本文中的程序是一个AAC码流解析程序.该程序可以从AAC码流中分析得到它的基本单元ADTS frame,并且 ...
- How do I create zip file in Servlet for download?
原文链接:https://kodejava.org/how-do-i-create-zip-file-in-servlet-for-download/ The example below is a s ...
- So sad! ,Asphyre Closure
So sad ! Asphyre Closure! 不过我相信开发App用Delphi应该是快的. 越与平台无关,优势越明显. 积累的组件市场. 虽然objc 有很多开源支持. 但总感觉还不够delp ...
- <tf-idf + 余弦相似度> 计算文章的相似度
背景知识: (1)tf-idf 按照词TF-IDF值来衡量该词在该文档中的重要性的指导思想:如果某个词比较少见,但是它在这篇文章中多次出现,那么它很可能就反映了这篇文章的特性,正是我们所需要的关键词. ...
- gcc编译 汇编 选项
gcc生成main.out的步骤分解:<blockquote>main.c-----(-S 编译)-------->main.s-------(-c 汇编)------->ma ...
- 配置文件Struts.xml 中type属性 redirect,redirectAction,chain的区别
1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失. 2.redirectAction:action处理完后重定向到一 ...
- 剑指offer-第五章总结
优化时间和空间效率的方法: 1,时间换空间. 2,动态规划. 3,找规律.