Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
使用Spring framework实现定时器功能

作者:未知 来源:月光软件站 加入时间:2005-6-5 月光软件站

采用Web自动加载TimerManager来管理Timer链,在Class更新服务器热加载后会发生异常。这要求对

TimerManager进行一些特殊的处理才能保证Timer链的正确性。

使用Spring framework中提供的TimerTask自动加载功能可以非常容易的实现定时器链的管理。同时,采用Spring framework的这一功能可以非常容易的对定时器进行添加、删除。

1.在Web.xml中申明

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/schedulingContext-timer.xml</param-value>
  </context-param>
  <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    <load-on-startup>3</load-on-startup>
  </servlet>

2.在schedulingContext-timer.xml描述用户的定时器

 <bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">
  <property name="scheduledTimerTasks">
   <list>
    <ref local="JorwangScheduledTimerTask1"/>
   </list>
  </property>
 </bean>

 <bean id="JorTimeTask1" class="workflow.common.MyTimer">
 </bean>
 <bean id="JorwangScheduledTimerTask1"   class="org.springframework.scheduling.timer.ScheduledTimerTask">
  <property name="timerTask"><ref bean="JorTimeTask1"/></property>
  <property name="delay"><value>10000</value></property>
  <property name="period"><value>86400000</value></property>
 </bean>

3.编写workflow.common.MyTimer定时器

这样就轻松完成了定时器的功能。如果需要修改、增加、删除定时器,只需要对2、3步的内容进行调整就可以

实现。




相关文章

相关软件