Websphere 8中的Spring调度间隔配置

时间:2013-08-12 14:15:48

标签: spring websphere scheduled-tasks

在Web球体上部署时,是否可以通过某些自定义属性指定固定延迟间隔或cron间隔模式。目前,在我的配置中,在应用程序上下文xml文件中指定了固定延迟间隔。但是,此文件将打包在EAR中,并且更改间隔将需要应用程序重新部署。

这是我的应用上下文文件:

<bean id="taskScheduler" class="org.springframework.scheduling.commonj.TimerManagerTaskScheduler"> 
    <property name="timerManager" ref="timerManager" />
</bean>
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
    <property name="workManager" ref="workManager" />
</bean>

<task:scheduled-tasks scheduler="taskScheduler">
    <task:scheduled ref="transactionProcessingService" method="processTransactions" fixed-delay="30000"/>
    <task:scheduled ref="transactionProcessingService" method="processOrderTransactions" fixed-delay="50000"/>
</task:scheduled-tasks>

感谢您的建议。

2 个答案:

答案 0 :(得分:1)

在您的应用程序上下文中添加以下内容

   <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="location" value="classpath:sample.properties"/>
          <property name="ignoreUnresolvablePlaceholders" value="true"/>
          <property name="ignoreResourceNotFound" value="true"/>
          <property name="order" value="0"/>
   </bean>

您的sample.properties文件

process_transactions = 30000
processOrder_transactions = 3000 

将以下内容替换为您的代码。

<task:scheduled-tasks scheduler="taskScheduler">
    <task:scheduled ref="transactionProcessingService" method="processTransactions" fixed-delay="${process_transactions}"/>
    <task:scheduled ref="transactionProcessingService" method="processOrderTransactions" fixed-delay="${processOrder_transactions}"/>
</task:scheduled-tasks>

答案 1 :(得分:0)

您可以使用<util:properties />标记从文件中加载属性:

  1. 将您的值移至某个属性文件(例如app.properties

    process_transactions=30000
    process_order_transactions=3000 
    
  2. 通过properties命名空间中的util标记加载它们(不要忘记declare util namespace

    <util:properties id="appConfig" location="classpath:app.properties" />
    
  3. 使用${variable}语法设置它们:

    <task:scheduled-tasks scheduler="taskScheduler">
        <task:scheduled ... fixed-delay="${process_transactions}"/>
        <task:scheduled ... fixed-delay="${process_order_transactions}"/>
    </task:scheduled-tasks>
    
  4. 编辑。正如@ user320587所解释的,我们可以通过在Websphere中使用JVM自定义属性来覆盖应用程序属性值(并避免重新开发):

      

    将此与systemPropertiesModeName属性一起使用   可以在PropertyPlaceHolderConfigurer中找到,我们可以避免   重新部署。我已将属性值设置为JVM Custom的一部分   Websphere中的属性和替换发生在   应用程序启动。所以,要更改间隔值,我可以修改   自定义属性值并重新启动应用程序。