自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

用Spring framework實(shí)現(xiàn)定時(shí)器功能

開發(fā) 后端
本文介紹用Spring framework實(shí)現(xiàn)定時(shí)器功能,以及在schedulingContext-timer.xml描述用戶的定時(shí)器。

采用Web自動加載TimerManager來管理Timer鏈,在Class更新服務(wù)器熱加載后會發(fā)生異常。這要求對TimerManager進(jìn)行一些特殊的處理才能保證Timer鏈的正確性。

使用Spring framework中提供的TimerTask自動加載功能可以非常容易的實(shí)現(xiàn)定時(shí)器鏈的管理。同時(shí),采用Spring framework的這一功能可以非常容易的對定時(shí)器進(jìn)行添加、刪除。

1.在Web.xml中申明

  1. <context-param>  
  2. <param-name>contextConfigLocation</param-name>  
  3. <param-value>/WEB-INF/schedulingContext-timer.xml</param-value>  
  4. </context-param>  
  5. <servlet>  
  6. <servlet-name>context</servlet-name>  
  7. <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>  
  8. <load-on-startup>3</load-on-startup>  
  9. </servlet> 

2.在schedulingContext-timer.xml描述用戶的定時(shí)器

  1. <bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">  
  2.   <property name="scheduledTimerTasks">  
  3.  ?。糽ist>  
  4.  ?。紃ef local="JorwangScheduledTimerTask1"/>  
  5. feedom.net  
  6.   </list>  
  7.  ?。?property>  
  8.  ?。?bean>  
  9.   <bean id="JorTimeTask1" class="workflow.common.MyTimer">  
  10.  ?。?bean>  
  11.  ?。糱ean id="JorwangScheduledTimerTask1" class="org.springframework.scheduling.timer.ScheduledTimerTask">  
  12.  ?。紁roperty name="timerTask"><ref bean="JorTimeTask1"/></property>  
  13.  ?。紁roperty name="delay"><value>10000</value></property>  
  14.   <property name="period"><value>86400000</value></property>  
  15.  ?。?bean> 

3.編寫workflow.common.MyTimer定時(shí)器

這樣就輕松用Spring framework完成了定時(shí)器的功能。如果需要修改、增加、刪除定時(shí)器,只需要對2、3步的內(nèi)容進(jìn)行調(diào)整就可以實(shí)現(xiàn)。

【編輯推薦】

  1. Spring Module 0.3版本發(fā)布
  2. 在Spring中XFire構(gòu)建Web Service
  3. Spring Web Services框架入門研究
  4. Sun GlassFish對Spring的支持
  5. 詳細(xì)介紹Spring的核心
責(zé)任編輯:佚名 來源: bitscn
相關(guān)推薦

2011-02-23 10:20:45

2009-06-15 15:02:48

Spring定時(shí)器

2021-07-27 16:01:29

高并發(fā)定時(shí)器高性能

2021-08-11 10:10:26

Linux定時(shí)器數(shù)組

2023-12-11 09:50:35

Linux定時(shí)器

2010-07-28 15:56:22

FlexTimer定時(shí)

2009-11-11 10:14:10

linux定時(shí)器操作系統(tǒng)

2016-09-12 14:07:14

Android 定時(shí)器

2009-04-12 08:51:50

Symbian諾基亞移動OS

2013-07-29 10:10:40

TCP協(xié)議TCP定時(shí)器TCP

2021-03-31 08:33:17

SysTick定時(shí)器SysTick定時(shí)器

2023-01-10 13:53:21

Linux定時(shí)器

2022-11-02 11:40:16

Flowable定時(shí)器流程

2009-07-17 14:38:49

Micro Frame

2023-08-02 09:26:03

軟件定時(shí)器鴻蒙

2023-02-28 18:09:53

Javascript定時(shí)器

2014-12-09 16:30:18

TCP定時(shí)器

2021-06-28 06:00:11

systemd定時(shí)器系統(tǒng)運(yùn)維

2021-04-18 12:12:29

systemd定時(shí)器系統(tǒng)運(yùn)維

2017-03-06 14:08:38

JavaScript單線程setTimeout
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號