JAVA学习网首页 把生活查询网加入收藏 把JAVA学习网设为首页 联系方式
    Hi,JAVA学习
JAVA基础 设计模式 数据库 JavaBeans J2EE JavaDelphi 用户界面 综合文章  
使用Spring framework实现定时器功能
时间:22/04/2007
作者:网络
来源:网络
小提示点这里把文章加入您的收藏夹,方便下次查看
设置文章字体大小:[ ]

采用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步的内容进行调整就可以

实现。


上一篇:EJB3笔记1-EJB3大变脸,实体Bean概念完全颠覆,EJB还有意义吗?

下一篇:创建跨平台的Ajax应用

  • 学习使用DispatchAction
  • 三步实现Cool Button
  • EnterpriseJavaBeansDistilled(3)
  • 一个表达式计算案例的设计和实现
  • JAVA:配置文件读取器
  • JSP实现树型组织架构(6)--包含文件connectinDB.jsp & orgConnInclude.jsp
  • hibernate基础_7
  • eclipse下tanghan plugin连mssql实战
  • J2EE到底是什么?
  • 小软件项目开发的管理
  • Effective Java读书笔记
  • Java常见问题集锦25问
  • [Creational Patterns] The Singleton
  • 在eclipse 3 上配置jsp开发环境
  • J2EE模式一瞥(5)
  • java中关于星期时间的操作
  • 根据petclinic项目手把手教你剖析SpringFramework源代码---日志篇
  • jetspeed开发实战
  • 返回】 【顶部】 【关闭
    Copyright © 2005-2010 www.594k.com All Rights Reserved.
    版权所有:JAVA学习网 备案序号:皖ICP备06004238号