Springboot中使用Scheduled做定时任务---http://www.cnblogs.com/lirenqing/p/6596557.html

已经验证的方案:

pom文件加入依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>

ExampleTimer.java

package com.example;

import java.text.SimpleDateFormat;
import java.util.Date; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; @Component
public class ExampleTimer {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedRate = 10000)
public void timerRate() {
System.out.println(dateFormat.format(new Date()));
} //第一次延迟1秒执行,当执行完后2秒再执行
@Scheduled(initialDelay = 1000, fixedDelay = 2000)
public void timerInit() {
System.out.println("init : "+dateFormat.format(new Date()));
} //每天20点16分50秒时执行
@Scheduled(cron = "50 16 20 * * ?")
public void timerCron() {
System.out.println("current time : "+ dateFormat.format(new Date()));
}
}

3、启动应用程序

启动程序,需要增加@EnableScheduling注解.

SpringBootScheduledApplication.java

定时任务-----Springboot中使用Scheduled做定时任务----http://www.cnblogs.com/lirenqing/p/6596557.html的更多相关文章

  1. Springboot中使用Scheduled做定时任务

    在开发中,定时任务是常见的功能,在spring boot 下开发定时任务其实很简单,具体代码如下: 1.配置依赖包pom.xml 由于默认的maven仓库经常访问不了,这里采用了阿里云的maven仓库 ...

  2. SpringBoot中使用@Scheduled创建定时任务

    SpringBoot中使用@Scheduled创建定时任务 定时任务一般会在很多项目中都会用到,我们往往会间隔性的的去完成某些特定任务来减少服务器和数据库的压力.比较常见的就是金融服务系统推送回调,一 ...

  3. SpringBoot之使用Scheduled做定时任务

    定时任务有好多开源框架比如Quartz,@Scheduled是Spring的一个定时任务注解,通过注解配置就能够轻量级的定时任务,简单方便. 一.@Scheduled注解介绍 这里先贴上@Schedu ...

  4. SpringBoot中使用task实现定时任务

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

  5. springboot中使用Scheduled定时任务

    一:在程序入口类中添加注解@EnableScheduling @SpringBootApplication @EnableScheduling public class DemoApplication ...

  6. SpringBoot中使用Scheduling执行定时任务

    SpringBoot自带的 Schedule,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多 以下任务都是在单线程下执行的 第一步 创建SpringBoot项目 第二步 外汇 ...

  7. spingboot中使用scheduled设置定时任务注意事项

    在spring开发过程中经常会遇到需要定时执行的任务,如定时生成报表,定时推送消息等任务. springboot 提供了简单的 @Scheduled 表达式来配置定时任务.该方式默认是单线程的,任务在 ...

  8. Spring Boot中使用@Scheduled创建定时任务

    我们在编写Spring Boot应用中经常会遇到这样的场景,比如:我需要定时地发送一些短信.邮件之类的操作,也可能会定时地检查和监控一些标志.参数等. 创建定时任务 在Spring Boot中编写定时 ...

  9. SpringBoot中Async异步方法和定时任务介绍

    1.功能说明 Spring提供了Async注解来实现方法的异步调用. 即当调用Async标识的方法时,调用线程不会等待被调用方法执行完成即返回继续执行以下操作,而被调用的方法则会启动一个独立线程来执行 ...

随机推荐

  1. HDU 2544 最短路 (Floyd)

    题意:略. 析:由于 n 比较小,所以我们可以用Floyd,完全不会超时. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240000 ...

  2. UI Design Do's and Don'ts

    转载自-Apple 官网,感觉不错,记录之 (https://developer.apple.com/design/tips/) Some useful design tips about IOS. ...

  3. bzoj 1673: [Usaco2005 Dec]Scales 天平【dfs】

    真是神奇 根据斐波那契数列,这个a[i]<=c的最大的i<=45,所以直接搜索即可 #include<iostream> #include<cstdio> usin ...

  4. 略微讲讲最近的 webpack 该如何加快编译

    首先假设 基础的环境是有 creat-react-app 所创建的 即所有基础的loader,插件的 cache 都已经缓存了 在这种情况下想加速,真是很难 不过,有一个插件是可以观察 各个模块所花的 ...

  5. [Usaco2018 Open]Talent Show

    Description FarmerJohn要带着他的N头奶牛,方便起见编号为1-N,到农业展览会上去,参加每年的达牛秀!他的第i头奶牛重量为wi,才艺水平为ti,两者都是整数.在到达时,Farmer ...

  6. Joseph UVA 1452 Jump

    题目传送门 /* 数学:约瑟夫环问题的变形,首先定义f[i]表示剩下i个人时,最后一个选出的人,有个公式:f[i] = (f[i-1] + m) % i f[1] = 0(编号从0开始),那么类似最后 ...

  7. Linux环境下安装JDK并配置环境变量

    首先查看是否已经安装了JDK并配置环境变量. [root@dhcc_plat opt]# java -version -bash: java: command not found [root@dhcc ...

  8. 用Movie显示gif(2)GifView

    1,类 import android.annotation.SuppressLint; import android.content.Context; import android.content.r ...

  9. 网站开发综合技术 HTML

    HTML            内容(Hyper Text Markup Language,超文本标记语言) CSS             网页美化 Javascript      脚本语言 第一部 ...

  10. hibernate一对多查询

    一对多查询 1,同时添加老师和学生案例 在进行具有关联关系的对象同时添加时 首先绑定对像间的关系 ---将多方关联一方 ---将一方关联多方 然后全部添加 备注: 1,保存老师对象时, 由于设置了学生 ...