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;
}
}

  



												

最新文章

  1. Windows Azure Service Bus (2) 队列(Queue)入门
  2. saiku 无密码登陆
  3. POJ 1743 (后缀数组+不重叠最长重复子串)
  4. [转]freemarker中的list
  5. hibernate 连接 oracle数据库
  6. 3A. Shortest path of the king
  7. 防止aspx木马的IIS SPY变态功能
  8. Spring Boot(5)一个极简且完整的后台框架
  9. 数据库部分(MySql)_3
  10. python3之Django基础篇
  11. go标准库的学习-crypto/sha256
  12. Java HTML to PDF 支持SVG
  13. Java基础编程题——水仙花数
  14. Linux pwn入门教程——CTF比赛
  15. Linux服务器同步时间
  16. : error C3861: “Sleep”: 找不到标识符
  17. Elasticsearch查询规则(一)match和term
  18. keepalived安装文档
  19. 设置PYTHONIOENCODING
  20. Oracle彻底卸载

热门文章

  1. Node的优点和缺点
  2. BZOJ5205 [CodePlus 2018 3 月赛]白金元首与莫斯科
  3. oracle时间问题 与case then
  4. 手写Spring事务框架
  5. asp.net相关的一些代码
  6. 数据中台核心方法论--OneModel为何需要产品化支撑?
  7. PHP curl_multi_info_read函数
  8. AcWing 224. 计算器 (BSGS算法)打卡
  9. 远程到Server系统安装和使用QTP
  10. (6)C++ 函数