用Spring framework实现定时器功能
2009-08-03 00:03
323 查看
采用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步的内容进行调整就可以实现。
使用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步的内容进行调整就可以实现。
相关文章推荐
- 用PHP实现定时器功能
- swift--Timer实现定时器功能,每个一段时间执行具体函数,可以重复,也可以只执行一次
- 利用millis()实现Arduino定时器功能
- asp.net web实现定时器功能
- android 中native层使用线程实现定时器功能
- Quartz定时器可视化管理功能的简单实现
- 不用写Windows服务实现定时器功能(FluentScheduler )
- Boost.deadline_timer实现定时器功能时需注意的时区问题
- Delphi的DLL里如何实现定时器功能?
- Codeblocks配置SDCC实现51单片机定时器功能(proteus仿真)
- 用PHP实现定时器功能
- libevent实现的简单定时器功能
- 文件批量上传的工具,要实现暂停继续、断点续传等功能(使用QtNetwork和QHttpMultiPart,和定时器检查超时)
- 用Spring framework实现定时器功能
- java spring实现定时器功能Timer
- 使用Spring的Quartz方式实现Java定时器功能
- 利用51系列单片机定时器功能实现测量脉冲宽度
- c++ 定时器 (简单功能实现)
- 轻松实现Rxjava定时器功能
- 使用单片机的定时器0和中断实现9到0的倒计时功能,并用数码管显示