Reputation: 1367
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.
Upvotes: 2
Views: 1558
Reputation: 7817
You can use <util:properties />
tag for loading properties from files:
Move your values to some property file (for example app.properties
)
process_transactions=30000
process_order_transactions=3000
load them via properties
tag from util
namespace (do not forget to declare util namespace)
<util:properties id="appConfig" location="classpath:app.properties" />
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.
Upvotes: 0
Reputation: 26094
Add the following in your application context
<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>
Your sample.properties file
process_transactions = 30000
processOrder_transactions = 3000
Replace the following with your code.
<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>
Upvotes: 1