1,启动spring容器

  Tomcat启动的时候,加载web.xml的listener和context-param,spring的listener监听到对应的contextConfigLocation创建事件后,开始启动spring容器;

  <listener>
  <description>spring监听器</description>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <context-param>
   <param-name>contextConfigLocation</param-name>
  <param-value>classpath:spring.xml</param-value>
  </context-param>

2,初始化定时任务相关的bean

                                      

3,初始化 org.springframework.scheduling.quartz.SchedulerFactoryBean

  参考    https://blog.csdn.net/beliefer/article/details/51578546 ;

  <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  <property name="triggers">
  <list>
  <ref bean="hitBeibeiTrigger" />
  <ref bean="hitBeibeiTrigger2" />
  </list>
  </property>
  <property name="configLocation" value="classpath:quartz.properties"/>
  </bean>

4,初始化 org.springframework.scheduling.quartz.CronTriggerFactoryBean

  <bean id="hitBeibeiTrigger"
  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
  <property name="jobDetail" ref="hitBeibeiJob"/>
  <property name="cronExpression" value="0/30 * * * * ?"/>
  </bean>   <bean id="hitBeibeiTrigger2"
   class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
  <property name="jobDetail" ref="hitBeibeiJob"/>
  <property name="cronExpression" value="0/30 * * * * ?"/>
  </bean>

5,初始化 org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean

  concurrent属性:true/false;参考 https://www.cnblogs.com/seeall/p/12084778.html

  <bean id="hitBeibeiJob"
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
  <property name="targetObject" ref="hitBeibeiScheduler"/>
  <property name="targetMethod" value="hit"/>
  <property name="concurrent" value="true"/>
  </bean>

6,hitBeibeiScheduler bean介绍

/**
* 用于测试定时任务:spring+quartz
*
* date 2019/12/23
*/
@Service(value = "hitBeibeiScheduler")
public class HitBeibeiScheduler implements ApplicationContextAware {
private static final Logger LOGGER = LoggerFactory.getLogger(HitBeibeiScheduler.class); private ApplicationContext applicationContext; // 执行job
public void hit() throws InterruptedException {
LOGGER.info("现在时间是" + DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss") + ", 打贝贝...");
Thread.sleep(60000);
LOGGER.info("现在时间是" + DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss")
+ ", 过去了60秒...");
} @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}

  



												

sping+quartz定时任务的最简单实践的更多相关文章

  1. Spring Boot 入门(九):集成Quartz定时任务

    本片文章续<Spring Boot 入门(八):集成RabbitMQ消息队列>,关于Quartz定时任务请参考<Quartz的基本使用之入门(2.3.0版本)> spring ...

  2. Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  3. Quartz定时任务学习(二)web应用

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  4. Quartz定时任务使用小记(11月22日)

    骤然接触quartz,先从小处着手,why,what,how quartz定时任务: 为什么使用quartz定时任务,以及定时任务在实际应用场景下的特定需求. 1.用户方面的需要,为了提供更好的使用体 ...

  5. 对quartz定时任务的初步认识

    已经好久没有写技术博文了,今天就谈一谈我前两天自学的quartz定时任务吧,我对quartz定时任务的理解,就是可以设定一个时间,然后呢,在这个时间到的时候,去执行业务逻辑,这是我的简单理解,接下来看 ...

  6. Java学习---Quartz定时任务快速入门

    Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2SE应用程序相结合也可以单独使用.Quartz可以用来创建简单或为运行十个,百个, ...

  7. Spring quartz定时任务service注入问题

    今天想单元测试一下spring中的quartz定时任务,job类的大致结构和下面的SpringQtz1类相似,我的是实现的org.quartz.Job接口,到最后总是发现job类里注入的service ...

  8. Thrift简单实践

    0.什么是RPC RPC(Remote Procedure Call - 远程过程调用),是通过网络从远程计算机上请求服务,而不需要了解底层网路技术的细节.简单点说,就是像调用本地服务(方法)一样调用 ...

  9. Java 异步处理简单实践

    Java 异步处理简单实践 http://www.cnblogs.com/fangfan/p/4047932.html 同步与异步 通常同步意味着一个任务的某个处理过程会对多个线程在用串行化处理,而异 ...

随机推荐

  1. jenkins发送邮箱配置,出现Error sending to the following VALID addresses,解决方案

    Jenkins发送邮箱配置,需要的插件:Extended E-mail Notification,邮件通知 1.Manage Jenkins -> Configure System 2.下图是“ ...

  2. Python 序列类型拆包 %s 和'{}'.format 的功能差异之一

    >>> 1, 2, 3 #这样写成一行相当于一个元组(1, 2, 3)>>> x = 1, 2, 3>>> x(1, 2, 3)>>& ...

  3. python3 实现简单ftp服务功能(服务端 For Linux)

    转载请注明出处! 功能介绍: 可执行的命令: lspwdcd put rm get mkdir 1.用户加密认证 2.允许多用户同时登陆 3.每个用户有自己的家目录,且只可以访问自己的家目录 4.运行 ...

  4. 矩阵(R语言)

    mymatrix <- matrix(vector, nrow=number_of_rows, ncol=number_of_columns,byrow=logical_value,dimnam ...

  5. leetcode-165周赛-1276-不浪费原料的汉堡制作方案

    题目描述: 自己的提交: class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List ...

  6. Vue学习笔记【33】——相关文章

    vue.js 1.x 文档 vue.js 2.x 文档 String.prototype.padStart(maxLength, fillString) js 里面的键盘事件对应的键码 Vue.js双 ...

  7. ldap yum安装-centos6

    yum安装openldap 系统环境信息 操作系统:CentOS release 6.7 基础的环境准备 iptables -F && /etc/init.d/iptables sav ...

  8. Mistakes Collection I

    Symbol =>'s meaning: what it used to be like => what it should be. 1) mistake array subscript: ...

  9. [CSP-S模拟测试41]题解

    中间咕的几次考试就先咕着吧…… A.夜莺与玫瑰 枚举斜率.只考虑斜率为正且不平行于坐标轴的直线,最后把$ans\times 2$再$+1$即可. 首先肯定需要用$gcd(i,j)==1$确保斜率的唯一 ...

  10. Angular项目中迭代生成的树,激活选中的节点,并将节点数据发送到父节点

    从后台返回的数据,还有多层子节点,需要一个生成树的组件,如果直接在页面上写循环来拼接感觉会很麻烦,因为数据的层级结构不固定. 参考网上其他人的方法,整理如下: 1. 创建一个用于循环迭代的组件,在父组 ...