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. A brief preview of the new features introduced by OpenGL 3.3 and 4.0

    A brief preview of the new features introduced by OpenGL 3.3 and 4.0   The Khronos Group continues t ...

  2. P2470 [SCOI2007]压缩

    传送门 区间dp,记\(dp(l,r,t)\)表示区间\((l,r)\),\(t\)表示这个区间中能不能放\(M\).如果可以,枚举中间哪里放\(M\)来压缩.也可以不压缩,后面直接跟上去.如果左右重 ...

  3. HDU 5514 欧拉函数应用

    前置技能: <=i且与i互质的数的和是phi(i)*i/2 思路: 显然每个人的步数是gcd(a[i],m) 把m的所有因数预处理出来 1~m-1中的每个数 只会被gcd(m,i)筛掉一遍 // ...

  4. Storm概念学习系列之核心概念(Tuple、Spout、Blot、Stream、Stream Grouping、Worker、Task、Executor、Topology)(博主推荐)

    不多说,直接上干货! 以下都是非常重要的storm概念知识. (Tuple元组数据载体 .Spout数据源.Blot消息处理者.Stream消息流 和 Stream Grouping 消息流组.Wor ...

  5. [转]URL最大长度问题

    本文转自:http://www.cnblogs.com/henryhappier/archive/2010/10/09/1846554.html 今天在测试Email Ticket的时候发现在进行Ma ...

  6. 《从Paxos到ZooKeeper 分布式一致性原理与实践》阅读【Leader选举】

    从3.4.0版本开始,zookeeper废弃了0.1.2这3种Leader选举算法,只保留了TCP版本的FastLeaderElection选举算法. 当ZooKeeper集群中的一台服务器出现以下两 ...

  7. LN : leetcode 258 Add Digits

    lc 258 Add Digits lc 258 Add Digits Given a non-negative integer num, repeatedly add all its digits ...

  8. Java内存模型原理,你真的理解吗?

    [51CTO.com原创稿件]这篇文章主要介绍模型产生的问题背景,解决的问题,处理思路,相关实现规则,环环相扣,希望读者看完这篇文章后能对 Java 内存模型体系产生一个相对清晰的理解,知其然知其所以 ...

  9. CF816B Karen and Coffee

    思路: 有点类似于区间修改点查询的树状数组. 实现: #include <iostream> #include <cstdio> using namespace std; ; ...

  10. 伪装IP进行投票

    伪装IP投票说明 1,目的 在访问网页链接进行投票时,网站往往对同一个IP的投票次数进行了限制,无法连续重复投票.为此可以使用“火狐浏览器+IP修改插件”,通过人为设置浏览器IP,绕过网站IP检查,可 ...