Search code examples
springwebspherescheduled-tasks

Spring scheduling interval configuration in Websphere 8


Is it possible to specify the fixed delay interval or the cron interval pattern through some custom properties when deployed on web sphere. Currently, in my configuration the fixed delay interval is specified on the application context xml file. However, this file will get packaged in an EAR and a change to interval would require application redeployment.

Here is my app context file:

<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>

Thanks for your suggestions.


Solution

  • You can use <util:properties /> tag for loading properties from files:

    1. Move your values to some property file (for example app.properties)

      process_transactions=30000
      process_order_transactions=3000 
      
    2. load them via properties tag from util namespace (do not forget to declare util namespace)

      <util:properties id="appConfig" location="classpath:app.properties" />
      
    3. set them using ${variable}syntax:

      <task:scheduled-tasks scheduler="taskScheduler">
          <task:scheduled ... fixed-delay="${process_transactions}"/>
          <task:scheduled ... fixed-delay="${process_order_transactions}"/>
      </task:scheduled-tasks>
      

    EDIT. As explained by @user320587 we can override application property value by using JVM Custom properties in Websphere (and avoid redeploiment):

    By using this along with the systemPropertiesModeName property available in the PropertyPlaceHolderConfigurer, we could avoid redeployment. I have set the property values as part of JVM Custom properties in Websphere and the substitution happens when the application is started. So, to change the interval value, I can modify the custom property value and restart the application.