SpringBoot 配置定时任务
SpringBoot启用定时任务,其内部集成了成熟的框架,因此我们可以很简单的使用它。
开启定时任务
@SpringBootApplication
//设置扫描的组件的包
@ComponentScan(basePackages = {"com.tao"})
//开启定时器任务
@EnableScheduling
public class MybatisPlusApplication {
public static void main(String[] args) {
SpringApplication.run(MybatisPlusApplication.class, args);
}
}
配置定时任务组件
使用注解@Component
可以定义一个组件,组件中,我们可以按照以下代码开始定时任务。
Cron 表达式可以使用:http://cron.qqe2.com/ 来生成,非常的方便
@Component
public class TaskScheduled {
private static final SimpleDateFormat sm = new SimpleDateFormat("HH:mm:ss");
/**
* 开始时间表达式,从第三秒开始每隔10s执行一次
*/
@Scheduled(cron = "3/10 * * * * ? ")
public void inputTime(){
System.out.println("当前系统时间:"+sm.format(System.currentTimeMillis()));
}
/**
* 时间间隔,每隔5秒执行一次
*/
@Scheduled(fixedRate = 5000)
public void inputTime2(){
System.out.println("当前系统时间:"+sm.format(System.currentTimeMillis()));
}
}
SpringBoot 配置定时任务的更多相关文章
- SpringBoot配置定时任务的两种方式
一.导入相关的jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- springboot配置定时任务并发执行
@Configuration public class ScheduleConfig implements SchedulingConfigurer { @Override public void c ...
- 在SpringBoot中配置定时任务
前言 之前在spring中使用过定时任务,使用注解的方式配置很方便,在SpringBoot中的配置基本相同,只是原来在spring中的xml文件的一些配置需要改变,在SpringBoot中也非常简单. ...
- springboot整合Quartz实现动态配置定时任务
前言 在我们日常的开发中,很多时候,定时任务都不是写死的,而是写到数据库中,从而实现定时任务的动态配置,下面就通过一个简单的示例,来实现这个功能. 一.新建一个springboot工程,并添加依赖 & ...
- 玩转SpringBoot之定时任务详解
序言 使用SpringBoot创建定时任务非常简单,目前主要有以下三种创建方式: 一.基于注解(@Scheduled) 二.基于接口(SchedulingConfigurer) 前者相信大家都很熟悉, ...
- SpringBoot整合定时任务和异步任务处理 3节课
1.SpringBoot定时任务schedule讲解 定时任务应用场景: 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类 ...
- 十三、springboot集成定时任务(Scheduling Tasks)
定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...
- SpringBoot创建定时任务
之前总结过spring+quartz实现定时任务的整合http://www.cnblogs.com/gdpuzxs/p/6663725.html,而springboot创建定时任务则是相当简单. (1 ...
- SpringBoot整合定时任务和异步任务处理
SpringBoot定时任务schedule讲解 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类 timer:配置比较麻烦,时间延后问题, ...
随机推荐
- [Swift]LeetCode9. 回文数 | Palindrome Number
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
- [Swift]LeetCode64. 最小路径和 | Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- [Swift]LeetCode388. 文件的最长绝对路径 | Longest Absolute File Path
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
- mysql怎么修改密码
第一种方式: 最简单的方法就是借助第三方工具Navicat for MySQL或Navicat Premium来修改,方法如下: 1.登录mysql到指定库,如:登录到student库. 2.然后点击 ...
- 在龙芯小本上安装Debain8.10
(图片是LEMOTE8089D笔记本,来自互联网) YX原来送了一个LEMOTE笔记本给我.CPU是首款真正的国产,龙芯2F,兼容mips的指令集. 笔记本原来的操作系统是Debian6,后来升级到了 ...
- WebSocket刨根问底(二)
上篇文章[WebSocket刨根问底(一)]中我们对WebSocket的一些基本理论进行了介绍,但是并没有过多的涉及到一些实战的内容,今天我希望能够用几个简单的案例来向小伙伴们展示下WebSocket ...
- JAVA数组和集合谁是儿子
Java有哪些数据存储方式? 基本数据类型(1byte3整2小数1字符1布尔)分别是byte,short,int long,flort,double,char,boolean(颜色好喜庆的样子O(∩_ ...
- [工具]PyCharm激活、注册码无效解决办法
前言 我是个 Pythoner,开发工具一直使用的 JetBrains 的 PyCharm.我师傅告诉过我:一个程序员一定要有一个用的很 6 的 IDE,你的开发效率会提高很多,很多... 我从小白的 ...
- Chapter 5 Blood Type——27
And then Mike staggered through the door, now supporting a sallow-looking Lee Stephens, another boy ...
- 精读《React PowerPlug 源码》
1. 引言 React PowerPlug 是利用 render props 进行更好状态管理的工具库. React 项目中,一般一个文件就是一个类,状态最细粒度就是文件的粒度.然而文件粒度并非状态管 ...