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. mysql limit 数据重复及遗漏

    某天写了一段CRUD,提测给QA,后来想起来忘记按规则排序了,然后修改了代码提交,这个时候QA扔给我一条狗,不,是一个BUG. 内心一片忧伤,CRUD也有BUG啊,怎么办怎么办,赶紧看看去. BUG描 ...

  2. oracle 数据库 锁

    首先你要知道表锁住了是不是正常锁?因为任何DML语句都会对表加锁. 你要先查一下是那个会话那个sql锁住了表,有可能这是正常业务需求,不建议随便KILL session,如果这个锁表是正常业务你把se ...

  3. linux部署jdk-tomcat

    http://blog.csdn.net/u012187452/article/details/72595040 //参考jdk下载 一.安装JDK1 下载安装包http://blog.csdn.ne ...

  4. MariaDB 管理

    在尝试运行MariaDB之前,首先确定其当前状态,运行或关闭. 有三个选项用于启动和停止MariaDB - 运行mysqld(MariaDB脚本). 运行mysqld_safe启动脚本. 运行mysq ...

  5. hdu 5885 XM Reserves (FFT建模)

    Problem Description As an eligible Ingress Resistance Agent you should know your power source, the E ...

  6. 芒果学院Python高级开发课程

  7. elasticsearch+kibana+fluentd 日志搜集集群搭建

    使用fluentd来搜集Nginx日志,准备3台服务器,列表如下 node1 elasticsearch/kibana/td-agent node2 td-agent/nginx node3 td-a ...

  8. Problem opening .cshtml files

    Hi Spartai, Welcome to MSDN forum. What is the version of your Visual Studio? It`s works fine for me ...

  9. 在使用 Eclisp 生成 实体(sql Server) 出现错误 :Unable to locate JAR/zip in file system as specified by the driver definition: sqljdbc.jar.

    错误: 解决方法: 第一步:点击 JAR List 第二步:  点击  Remove  JAR/ZIP 第三步: 再添加一下 sqljdbc.jar

  10. ES6数组中删除指定元素

    知识点: ES6从数组中删除指定元素 findIndex()方法返回数组中满足提供的测试函数的第一个元素的索引.否则返回-1. arr.splice(arr.findIndex(item => ...