SpringBoot整合定时任务task

  1. 使用注解EnableScheduling在启动类上.
  2. 定义@Component作为组件被容器扫描.
  3. 表达式生成地址: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(十)的更多相关文章

  1. SpringBoot整合全局异常处理&SpringBoot整合定时任务Task&SpringBoot整合异步任务

    ============整合全局异常=========== 1.整合web访问的全局异常 如果不做全局异常处理直接访问如果报错,页面会报错500错误,对于界面的显示非常不友好,因此需要做处理. 全局异 ...

  2. spring boot 初试,springboot入门,springboot helloworld例子

    因为项目中使用了spring boot ,之前没接触过,所以写个helloworld玩玩看,当做springboot的一个入门例子.搜索 spring boot.得到官方地址:http://proje ...

  3. SpringBoot几种定时任务的实现方式

    定时任务实现的几种方式: Timer:这是java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务.使用这种方式可以让你的程序按照某一个频度执行, ...

  4. SpringBoot中的定时任务与Quartz的整合

    SpringBoot集成Quartz 定时任务Quartz : 就是在指定的时间执行一次或者循环执行,在项目的开发中有时候会需要的, 还是很有用的. SpringBoot内置的定时 添加依赖 < ...

  5. SpringBoot系列——动态定时任务

    前言 定时器是我们项目中经常会用到的,SpringBoot使用@Scheduled注解可以快速启用一个简单的定时器(详情请看我们之前的博客<SpringBoot系列--定时器>),然而这种 ...

  6. springBoot中的定时任务

    springBoot中的定时任务 1:在Spring Boot的主类中加入@EnableScheduling注解,启用定时任务的配置 2:新建ScheduledTasks任务类 : package c ...

  7. SpringBoot Docker入门,SpringBoot Docker安装

    SpringBoot Docker入门,SpringBoot Docker安装 ================================ ©Copyright 蕃薯耀 2018年4月8日 ht ...

  8. SpringBoot中执行定时任务

    一:在SpringBoot中使用定时任务相当的简单.首先,我们在启动类中加入@EnableScheduling来开启定时任务. @SpringBootApplication @EnableSchedu ...

  9. springboot整合@Scheduled定时任务的使用

    1.启动类里面添加注解@EnableScheduling ,例如: @SpringBootApplication@EnableScheduling@MapperScan("com.examp ...

随机推荐

  1. Js中的undefined和not defined

    1.undefined 已经声明,但未赋值 2.not defined 未声明,报错

  2. 使用 Dom4j 将 XML 转换为 MAP

    本文为转载:http://blog.sina.com.cn/s/blog_6145ed810100z164.html  原文地址. 自己仅作备忘录方便查找留了一份. 这是解析Xml 的辅助类 pack ...

  3. luogu2093 [国家集训队]JZPFAR

    题面不符?-- #include <algorithm> #include <iostream> #include <cstdio> using namespace ...

  4. Session超时和莫名丢失的原因与处理办法

    原因: 改动global.asax,Web.config,bin目录里的东西,导致Web Applicatioin重启. 有些杀毒软件会去扫描你的Web.config文件,也会导致Session丢失. ...

  5. bash shell命令与监测的那点事(一)

    bash shell命令与监测的那点事之ps 学习LInux,不得不谈谈bash shell命令,介绍Linux命令行与Shell脚本的书有很多很多,bash shell命令也有很多,此次我们只谈谈有 ...

  6. 理解机器为什么可以学习(四)---VC Dimension

    前面一节我们通过引入增长函数的上限的上限,一个多项式,来把Ein 和 Eout 的差Bound住,这一节引入VC Bound进一步说明这个问题. 前边我们得到,如果一个hypethesis集是有bre ...

  7. 爬虫:Scrapy3 - Items

    Item 对象是种简单的容器,保存了爬取到得数据.其提供了类似于词典(dictionary-like)的API以及用于声明可用字段的简单语法. 声明Item import scrapy class P ...

  8. python中 in, any 和 all用法

    in if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') any if x or y o ...

  9. Log4j官方文档翻译(九、输出到数据库)

    log4j提供了org.apache.log4j.JDBCAppender对象,可以把日志输出到特定的数据库. 常用的属性: bufferSize 设置buffer的大小,默认是1 driver 设置 ...

  10. Mysql 数据库备份工具 xtrabackup

    1.安装测试数据库mysql5.7 详细步骤 yum install -y gcc gcc-c++ cmake bison ncurses-devel .tar.gz cd mysql-/ cmake ...