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

来源:互联网 发布:python中文手册 编辑:程序博客网 时间:2024/06/05 02:37
在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 0
原创粉丝点击