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]LeetCode200.岛屿的个数 | Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- [Swift]LeetCode285. 二叉搜索树中的中序后继节点 $ Inorder Successor in BST
Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Th ...
- [Swift]LeetCode547. 朋友圈 | Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is t ...
- 小程序自定义pick(日期加时间组合)
最近小程序有个需求要使用日期加时间的pick组件 翻了小程序文档似乎没有符合的 手写一个 新建组件picker.js: Component({ properties: { disabled: { t ...
- 【Maven】---Nexus私服配置Setting和Pom
maven---nexus私服配置setting和pom 上一遍博客已经在linux服务器上,搭建好nexus私服了,博客地址:Linux搭建Nexus3.X私服 现在就需要配置setting.xml ...
- 『Pushing Boxes 双重bfs』
Pushing Boxes Description Imagine you are standing inside a two-dimensional maze composed of square ...
- asp.net core 系列 15 中间件
一.概述 中间件(也叫中间件组件)是一种装配到应用管道以处理请求和响应的软件. 每个组件:(1)选择是否将请求传递到管道中的下一个组件;(2)可以在管道中的下一个组件之前和之后执行工作. 请求委托用于 ...
- Error: Default interface methods are only supported starting with Android N (--min-api 24): java.io.InputStream org.apache.poi.sl.usermodel.ObjectShape.readObjectData()
项目运行的时候,如果报错 Error: Default interface methods are only supported starting with Android N (--min-api ...
- JAVA实现在线查看PDF和office文档
一个项目中要做一个在线预览附件(和百度文库差不多)的小功能点,楼主在开发过程中踩了很多坑的同时也总结了一些方法,仅供广大猿友参考,那么要实现这个小功能,目前主要是有如下3种可行的实现方式,下面先说实现 ...
- hdu:2036.改革春风吹满地
Problem Description “ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里 ...