Spring自带定时器任务:

code:

  1. import org.springframework.beans.factory.annotation.Configurable;
  2. import org.springframework.scheduling.annotation.EnableScheduling;
  3. import org.springframework.scheduling.annotation.Scheduled;
  4. import org.springframework.stereotype.Component;
  5.  
  6. import java.text.SimpleDateFormat;
  7. import java.util.Date;
  8.  
  9. @Component
  10. @Configurable
  11. @EnableScheduling
  12. public class ScheduledTasks{
  13.  
  14. @Scheduled(fixedRate = 1000 * 30)
  15. public void reportCurrentTime(){
  16. System.out.println ("Scheduling Tasks Examples: The time is now " + dateFormat ().format (new Date()));
  17. }
  18.  
  19. //每1分钟执行一次
  20. @Scheduled(cron = "0/4 * * * * * ")
  21. public void reportCurrentByCron(){
  22. System.out.println ("Scheduling Tasks Examples By Cron: The time is now " + dateFormat ().format (new Date ()));
  23. }
  24.  
  25. private SimpleDateFormat dateFormat(){
  26. return new SimpleDateFormat ("HH:mm:ss");
  27. }
  28. }

Output:

  1. Scheduling Tasks Examples By Cron: The time is now 12:02:48
  2. Scheduling Tasks Examples By Cron: The time is now 12:02:52
  3. Scheduling Tasks Examples: The time is now 12:02:54
  4. Scheduling Tasks Examples By Cron: The time is now 12:02:56
  5. Scheduling Tasks Examples By Cron: The time is now 12:03:00
  6. Scheduling Tasks Examples By Cron: The time is now 12:03:04
  7. Scheduling Tasks Examples By Cron: The time is now 12:03:08
  8. Scheduling Tasks Examples By Cron: The time is now 12:03:12
  9. Scheduling Tasks Examples By Cron: The time is now 12:03:16
  10. Scheduling Tasks Examples By Cron: The time is now 12:03:20
  11. Scheduling Tasks Examples By Cron: The time is now 12:03:24
  12. Scheduling Tasks Examples: The time is now 12:03:24
  13. Scheduling Tasks Examples By Cron: The time is now 12:03:28

Quartz:

使用quartz实现定时任务。
  Quartz设计者做了一个设计选择来从调度分离开作业。Quartz中的触发器用来告诉调度程序作业什么时候触发。框架提供了一把触发器类型,但两个最常用的是SimpleTrigger和CronTrigger。

SimpleTrigger为需要简单打火调度而设计。典型地,如果你需要在给定的时间和重复次数或者两次打火之间等待的秒数打火一个作业,那么SimpleTrigger适合你。另一方面,如果你有许多复杂的作业调度,那么或许需要CronTrigger。
       CronTrigger是基于Calendar-like调度的。当你需要在除星期六和星期天外的每天上午10点半执行作业时,那么应该使用CronTrigger。正如它的名字所暗示的那样,CronTrigger是基于Unix克隆表达式的。

http://blog.csdn.net/github_34889651/article/details/52586234

https://my.oschina.net/hhaijun/blog/698498

http://www.jianshu.com/p/67c760de79d5

http://blog.csdn.net/loongshawn/article/details/52078134

http://www.cnblogs.com/lic309/p/4089633.html

SpringBoot中的Quartz应用的更多相关文章

  1. SpringBoot中使用Quartz笔记

    Quartz可以用来做什么? Quartz是一个任务调度框架,可用来做定时任务. 吧啦吧啦......... 还是直接上代码. application.properties  配置文件. * * ? ...

  2. 在springboot项目中引入quartz任务调度器。

    quartz是一个非常强大的任务调度器.我们可能使用它来管理我们的项目,常见的是做业绩统计等等.当然它的功能远不止这些.我们在这里不介绍quartz的原理,下面讲讲如何在springboot中使用qu ...

  3. SpringBoot定时任务 - 集成quartz实现定时任务(单实例和分布式两种方式)

    最为常用定时任务框架是Quartz,并且Spring也集成了Quartz的框架,Quartz不仅支持单实例方式还支持分布式方式.本文主要介绍Quartz,基础的Quartz的集成案例本,以及实现基于数 ...

  4. SpringBoot中yaml配置对象

    转载请在页首注明作者与出处 一:前言 YAML可以代替传统的xx.properties文件,但是它支持声明map,数组,list,字符串,boolean值,数值,NULL,日期,基本满足开发过程中的所 ...

  5. 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧

    做WEB项目,一定都用过JSP这个大牌.Spring MVC里面也可以很方便的将JSP与一个View关联起来,使用还是非常方便的.当你从一个传统的Spring MVC项目转入一个Spring Boot ...

  6. springboot中swaggerUI的使用

    demo地址:demo-swagger-springboot springboot中swaggerUI的使用 1.pom文件中添加swagger依赖 2.从github项目中下载swaggerUI 然 ...

  7. 项目中使用Quartz集群分享--转载

    项目中使用Quartz集群分享--转载 在公司分享了Quartz,发布出来,希望大家讨论补充. CRM使用Quartz集群分享  一:CRM对定时任务的依赖与问题  二:什么是quartz,如何使用, ...

  8. (4) Spring中定时任务Quartz集群配置学习

    原 来配置的Quartz是通过spring配置文件生效的,发现在非集群式的服务器上运行良好,但是将工程部署到水平集群服务器上去后改定时功能不能正常运 行,没有任何错误日志,于是从jar包.JDK版本. ...

  9. Spring 中使用Quartz实现任务调度

    前言:Spring中使用Quartz 有两种方式,一种是继承特定的基类:org.springframework.scheduling.quartz.QuartzJobBean,另一种则不需要,(推荐使 ...

随机推荐

  1. 新建虚拟机_WIN7 32位系统

    准备工作:下载win7 32位纯净版镜像文件 大部分步骤与安装XP系统相似,此处只说明一下不同: 创建好虚拟机后启动有报错:CHS data ERROR,无法从CD/DVD启动 编辑虚拟机--> ...

  2. grunt学习三-bower(二)

    一.通过bower help 来展开bower的命令 Usage: bower <command> [<args>] [<options>] Commands: c ...

  3. SQL SERVER分区详解(1-5)

    转自: (五)SQL Server分区自动化案例     (四)SQL Server分区管理     (三)索引分区知识详解     (二)SQL Server分区创建过程     (一)SQL Se ...

  4. js-jquery-对象与JSON字符串互相转换

    1:jQuery插件支持的转换方式 代码如下: String→Object$.parseJSON( jsonstr ); //jQuery.parseJSON(jsonstr),可以将json字符串转 ...

  5. spring boot上传 下载图片。

    https://blog.csdn.net/a625013/article/details/52414470 build.gradle buildscript { repositories { mav ...

  6. 如何减少block的嵌套层次?

    1.首先了解一个概念 函数式反应型编程(FRP) —— 实时互动应用开发的新思路 http://www.infoq.com/cn/articles/functional-reactive-progra ...

  7. JS中“==”和“===”的原理和区别

    1.为什么讨论这个问题? - 有个说法,尽量不用==,而使用===,是这样吗? 2.分析问题,原理是什么? 下面说说ECMAScript 5 language specification里的说明: 1 ...

  8. VS2010/MFC编程入门之三十九(文档、视图和框架:概述)

    前面几节讲了菜单.工具栏和状态栏的使用,鸡啄米本节开始将为大家讲解文档.视图和框架的知识. 文档.视图和框架简介 在VS2010/MFC编程入门之三十四(菜单:VS2010菜单资源详解)创建的单文档工 ...

  9. 公司里面用的iTextSharp(教程)---简介

    一.需求: 公司这次要做一个生成PDF的功能,需要设计,刚刚进入公司,组长把任务分配给了我,为了完成这个任务,苦学了许久的iTextSharp.现在记录下实现过程中了了解的一些东东,一起分享哈~~ 二 ...

  10. 查看Tensorflow版本

    python -c 'import tensorflow as tf; print(tf.__version__)' # for Python 2 python3 -c 'import tensorf ...