java – Upgrading to springframework.scheduling.concurrent?

java – Upgrading to springframework.scheduling.concurrent?

Use org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean in place of org.springframework.scheduling.timer.TimerFactoryBean and use org.springframework.scheduling.concurrent.ScheduledExecutorTask in place of org.springframework.scheduling.timer.ScheduledTimerTask. You will need to adjust the property names and values as needed but, that should be pretty self evident.

Optionally, you could refactor your com.example.OnlineTimerTask to not extend java.util.TimeTask as the ScheduledTimerTask only requires a runnable.

Spring 4 configuration – Below configuration working after spring migration from 3.2.x to 4.6.x

<bean id=schedulerTask>
        <property name=targetObject ref=springJmsListnerContainer />
        <property name=targetMethod value=execute />
    <bean id=timerTask class=org.springframework.scheduling.concurrent.ScheduledExecutorTask>
        <property name=runnable ref=schedulerTask />
        <property name=delay value=100 />
        <property name=period value=60000 />
    <bean class=org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean>
        <property name=scheduledExecutorTasks>
                <ref bean=timerTask />

java – Upgrading to springframework.scheduling.concurrent?

The answer is – add one runnable field

 <bean id=scheduledExecutorTask 
    <!-- wait 10 milli seconds before starting repeated execution -->
    <property name=delay>
    <!-- run every 1 second -->
    <property name=period>
    <property name=runnable>
        <ref bean=checkInvokingTask/>

Leave a Reply

Your email address will not be published. Required fields are marked *