项目经验:项目预警定时器配置要点总结

在web.xml下


<!-- context-param是配置Spring的applicationContext文件,如果不配默认位置是WEB-INF下的applicationContext.xml文件 -->

     <context-param >

            <param-name >contextConfigLocation </param-name >

            <param-value >

                 classpath*:configs /applicationContext-app.xml

            </param-value >

     </context-param >

     <listener >

           <listener-class >org.springframework.web.context.ContextLoaderListener </listener-class >

     </listener >

 

 

在applicationContext-app.xml 下





<!-- 启动定时器 -->


     
<bean class= "org.springframework.scheduling.quartz.SchedulerFactoryBean" >

           
<property name ="triggers">

                
<list >

                
<ref local ="projectEsWarningTrigger"/>   

                
<ref local ="dataDelayWarningTrigger"/>

                
</list >

           
</property >

     
</bean >

     


     
<!-- 定义我们要运行的类,可以使用注入,定制一些参数    项目超标预警-->

     
<bean id ="projectEsWarning" class= "com.richway.rtmonitor.util.ProjectESWarning" >

           
<property name ="param" value="Spring定时器配置项目超标预警" ></property >

           
<property name ="yjlsxxService" ref="yjlsxxService"/>

     
</bean >

     


     
<!-- 定义我们要运行的类,可以使用注入,定制一些参数    数据延迟预警-->

     
<bean id ="dataDelayWarning" class= "com.richway.rtmonitor.util.DataDelayWarning" >

           
<property name ="param" value="Spring定时器配置数据延迟预警" ></property >

           
<property name ="yjlsxxService" ref="yjlsxxService"/>

     
</bean >

     


     


     
<!-- 引用、配置要运行的方法   项目超标预警-->

     
<bean id ="projectEsWarningDetail" class= "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >

     
  <!-- 目标对象 -->

     
  <!-- 指定任务类 -->

           
  <property name ="targetObject">

                
     <ref bean ="projectEsWarning"/>

           
  </property >

     
  <!-- 是否同时发生 -->

           
  <property name ="concurrent" value="false"></ property>

     
  <!-- 目标方法 -->

           
  <property name ="targetMethod" value="run"></ property>

     
</bean >

     


     
<!-- 引用、配置要运行的方法   数据延迟预警-->

     
<bean id ="dataDelayWarningDetail" class= "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >

     
  <!-- 目标对象 -->

     
  <!-- 指定任务类 -->

           
  <property name ="targetObject">

                
    <ref bean ="dataDelayWarning"/>

           
  </property >

     
  <!-- 是否同时发生 -->

           
  <property name ="concurrent" value="false"></ property>

     
  <!-- 目标方法 -->

           
  <property name ="targetMethod" value="run"></ property>

     
</bean >

     


     
<!-- 引用、定制时间间隔  项目超标预警 每隔5秒一次 -->

     
<bean id ="projectEsWarningTrigger" class= "org.springframework.scheduling.quartz.CronTriggerBean" >

           
  <property name ="jobDetail">

                
    <ref bean ="projectEsWarningDetail"/>

           
  </property >

           
  <property name ="cronExpression">

                
   <value >0/5 * * * * ? </value >

           
  </property >

     
</bean >

     


     
<!-- 引用、定制时间间隔  数据延迟预警 中午12点 以及 晚上12点 执行各执行一次  下面被注释掉的那一行就是凌晨0点 中午12点 各执行一次  另外一行 下午三点 每隔5分钟 执行一次 只是为了测试用-->

     
<bean id ="dataDelayWarningTrigger" class= "org.springframework.scheduling.quartz.CronTriggerBean" >

           
  <property name ="jobDetail">

                
   <ref bean ="dataDelayWarningDetail"/>

           
  </property >

           
  <property name ="cronExpression">

                
    <!-- <value>0 0 0,12 * * ?</value> -->

                
    <value >0 5,10,15,20,25,30,35,40,45,50,55 15 * * ?</value>

           
  </property >
     

</bean >


 

 
在DataDelayWarning.java 下 
 
package com.richway.rtmonitor.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Results;

import com.richway.rtmonitor.service.ZxDYjlsxxService;

/**
* @author lej
*
* 2014-7-9上午9:58:02
*/
@ParentPackage("globestruts")
@Namespace("/rtmonitor/yjlsxx")
@Results({})
public class DataDelayWarning {
    
     private String param;

     private ZxDYjlsxxService yjlsxxService;

     public void setYjlsxxService(ZxDYjlsxxService yjlsxxService) {
          this.yjlsxxService = yjlsxxService;
     }

     public String getParam() {
          return param;
     }

     public void setParam(String param) {
          this.param = param;
     }

     public void run() throws Exception {
          // 打印信息
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          System.out.println("the param is:" + param + " ! Time is "
                    + format.format(new Date()));
         
          System.out.println("数据延迟预警方法开始");
          yjlsxxService.createDataDelayWarning();
     }
}

 
 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值