论坛首页 Java企业应用论坛

彻底理解spring的定制任务(scheduling)

浏览 25282 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-08-02  
<bean id="infoCenterAutoBuildTask"   
    class="com.teesoo.teanet.scheduling.InfoCenterAutoBuildTask">   
    <property name="baseService" ref="baseService" />   
    <property name="htmlCreator" ref="htmlCreator" />   
</bean>   
   
<bean id="scheduledTask"   
    class="org.springframework.scheduling.timer.ScheduledTimerTask">   
    <!-- wait 10 seconds before starting repeated execution -->   
    <property name="delay" value="10000" />   
    <!-- run every 50 seconds -->   
    <property name="period" value="1000000" />   
    <property name="timerTask" ref="infoCenterAutoBuildTask" />   
</bean>   
   
   
<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">   
   <property name="scheduledTimerTasks">   
       <list>   
           <!-- see the example above -->   
           <ref bean="scheduledTask" />   
       </list>   
   </property>   
</bean> 
 

还可以这样配置吧:
<bean id="infoCenterAutoBuildTaskFactory" class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">   
    <property name="targetObject">
         <ref bean="infoCenterAutoBuildTask"/>
    </property>
    <property name="targetMethod">
	<value>your taskMethod</value>
    </property>
</bean>   

<bean id="infoCenterAutoBuildTask"   
    class="com.teesoo.teanet.scheduling.InfoCenterAutoBuildTask">   
    <property name="baseService" ref="baseService" />   
    <property name="htmlCreator" ref="htmlCreator" />   
</bean>      

<bean id="scheduledTask"   
    class="org.springframework.scheduling.timer.ScheduledTimerTask">   
    <!-- wait 10 seconds before starting repeated execution -->   
    <property name="delay" value="10000" />   
    <!-- run every 50 seconds -->   
    <property name="period" value="1000000" />   
    <property name="timerTask" ref="infoCenterAutoBuildTaskFactory" />   
</bean>   
   
   
<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">   
   <property name="scheduledTimerTasks">   
       <list>   
           <!-- see the example above -->   
           <ref bean="scheduledTask" />   
       </list>   
   </property>   
</bean> 
 

0 请登录后投票
   发表时间:2007-08-03  
cherami 写道
我记得spring是使用Quartz作为任务调度的内部实现的


Spring支持Timer和Quartz

Quartz功能更为强大。
0 请登录后投票
   发表时间:2007-08-08  
启动服务后,ScheduledTimerTask是不是第一次设置了delay和period后就无法修改了呢
0 请登录后投票
   发表时间:2007-08-08  
  spring的定制任务,有时并不灵活,在几个项目中使用发现有以下问题
 1、经常会运行一段时间后,不再调度运行了。怀疑是run()方法中的业务处理有异常引起的。
 2、和使用一个thread来控制作循环来讲,后者更加灵活一些,特别是不需要做同步处理。
0 请登录后投票
   发表时间:2007-08-08  
spring的定时任务在具体项目时还是有不少不足的地方。我最近这星期在搞定时任务+任务配置的开发,像收费的账户定时冲账,服务自动停断,欠费催缴等.当需要随意配置任务,以及任意时间执行时,用spring那种配置方法就很不好用了,因为spring都是写死在配置文件中。而且像web服务器死了,任务来不及执行等各种情况,我想spring的定制任务是没法处理的。还有像集群这种情况,我想也是不好处理。所以我现在只能用quartz+db来实现,搞了一个星期了,快搞完了。搞完后,我把代码整理出来,我相信会有不少人遇到我这样的项目,大家互相交流一下吧。
0 请登录后投票
   发表时间:2007-08-09  
呵呵,我用python来写调度脚本,代码行数比spring配置文件行数还小很多,很稳定、跨平台,想怎么跑就怎么跑
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics