(入门SpringBoot)SpringBoot结合定时任务task(十)
SpringBoot整合定时任务task
- 使用注解EnableScheduling在启动类上.
- 定义@Component作为组件被容器扫描.
- 表达式生成地址:http://cron.qqe2.com
下面是例子:
1. //开启定时任务:
@EnableScheduling
public class DemoApplication {
2./**
* 定时任务:
*/
@Component
public class TestTask {
private static final SimpleDateFormat dataFormat = new SimpleDateFormat("HH:mm:ss");
//定义每3秒执行任务:
@Scheduled(fixedRate = 3000)
public void reportCurrentTime(){
System.out.println("现在时间:" + dataFormat.format(new Date()));
}
}
3.启动就完事了.
提示: 定时任务可以用cron表达式:@Scheduled(cron = "")
(入门SpringBoot)SpringBoot结合定时任务task(十)的更多相关文章
- SpringBoot整合全局异常处理&SpringBoot整合定时任务Task&SpringBoot整合异步任务
============整合全局异常=========== 1.整合web访问的全局异常 如果不做全局异常处理直接访问如果报错,页面会报错500错误,对于界面的显示非常不友好,因此需要做处理. 全局异 ...
- spring boot 初试,springboot入门,springboot helloworld例子
因为项目中使用了spring boot ,之前没接触过,所以写个helloworld玩玩看,当做springboot的一个入门例子.搜索 spring boot.得到官方地址:http://proje ...
- SpringBoot几种定时任务的实现方式
定时任务实现的几种方式: Timer:这是java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务.使用这种方式可以让你的程序按照某一个频度执行, ...
- SpringBoot中的定时任务与Quartz的整合
SpringBoot集成Quartz 定时任务Quartz : 就是在指定的时间执行一次或者循环执行,在项目的开发中有时候会需要的, 还是很有用的. SpringBoot内置的定时 添加依赖 < ...
- SpringBoot系列——动态定时任务
前言 定时器是我们项目中经常会用到的,SpringBoot使用@Scheduled注解可以快速启用一个简单的定时器(详情请看我们之前的博客<SpringBoot系列--定时器>),然而这种 ...
- springBoot中的定时任务
springBoot中的定时任务 1:在Spring Boot的主类中加入@EnableScheduling注解,启用定时任务的配置 2:新建ScheduledTasks任务类 : package c ...
- SpringBoot Docker入门,SpringBoot Docker安装
SpringBoot Docker入门,SpringBoot Docker安装 ================================ ©Copyright 蕃薯耀 2018年4月8日 ht ...
- SpringBoot中执行定时任务
一:在SpringBoot中使用定时任务相当的简单.首先,我们在启动类中加入@EnableScheduling来开启定时任务. @SpringBootApplication @EnableSchedu ...
- springboot整合@Scheduled定时任务的使用
1.启动类里面添加注解@EnableScheduling ,例如: @SpringBootApplication@EnableScheduling@MapperScan("com.examp ...
随机推荐
- nable to execute dex: Multiple dex files define Lcom/chinaCEB/cebActivity/R
用proguaid 只混淆Android项目的src下的包的话,如果出现了上面的问题: nable to execute dex: Multiple dex files define Lcom/chi ...
- uoj206 [APIO2016]最大差分
ref #include "gap.h" #include <iostream> #include <cstdio> using namespace std ...
- Python-S9——Day84-ORM项目实战之权限、form以及modelform
01 权限菜单显示 02 Django路径的自动添加问题 03 原生form实现增删改查 04 modelform实现增删改查 01 权限菜单显示 1.1 优先查找项目中的templates,如果没有 ...
- python 笔试总结
1.对比两种函数对应结果 def fn(x): if x>0: print(x) fn(x-1) ****结果****** 3 2 1 $$$$$$另外一种$$$$$$$$$ def fn(x) ...
- hnust 懒人多动脑
问题 F: 懒人得多动脑 时间限制: 1 Sec 内存限制: 128 MB提交: 93 解决: 30[提交][状态][讨论版] 题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每 ...
- python3.x与python2.x的区别(转)
转自:http://www.cnblogs.com/codingmylife/archive/2010/06/06/1752807.html 1.性能 Py3.0运行 pystone benchmar ...
- Solr配置Ikanalyzer分词器
上一篇文章讲解在win系统中如何安装solr并创建一个名为test_core的Core,接下为text_core配置Ikanalyzer 分词器 1.打开text_core的instanceDir目录 ...
- 练习题 - js函数
代码贴出来 1 function Cat() { 2 getColor = function(){ console.log(1);} 3 return this; 4 } 5 Cat.getColor ...
- php开启子进程处理
$pageNum = ceil($totalNum/$pageSize); for($page=1;$page<=$pageNum;$page++){ $this->o_pcntl-> ...
- 用最优方法从LinkedList列表中删除重复元素
用运行速度最优的方法从LinkedList列表里删除重复的元素,例如A->B->BB->B->C,返回A->B->BB->C. 考试的时候没完全想明白,考完又 ...