Upgrading to springframework.scheduling.concurrent?

前端 未结 3 1401
谎友^
谎友^ 2021-02-07 11:37

As of Spring 3.0 the ScheduledTimerTask is deprecated and I can\'t understand how to upgrade to org.springframework.scheduling.concurrent.

    

        
相关标签:
3条回答
  • 2021-02-07 12:05

    The answer is - add one "runnable" field

     <bean id="scheduledExecutorTask" 
        class="org.springframework.scheduling.concurrent.ScheduledExecutorTask">
        <!-- wait 10 milli seconds before starting repeated execution -->
        <property name="delay">
            <value>10</value>
        </property>
        <!-- run every 1 second -->
        <property name="period">
            <value>1000</value>
        </property>
        <property name="runnable">
            <ref bean="checkInvokingTask"/>
        </property>
    </bean>
    
    0 讨论(0)
  • 2021-02-07 12:12

    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.

    0 讨论(0)
  • 2021-02-07 12:25

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

    <bean id="schedulerTask"
            class="org.springframework.scheduling.support.MethodInvokingRunnable">
            <property name="targetObject" ref="springJmsListnerContainer" />
            <property name="targetMethod" value="execute" />
        </bean>
        <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>
        <bean class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean">
            <property name="scheduledExecutorTasks">
                <list>
                    <ref bean="timerTask" />
                </list>
            </property>
        </bean>
    
    0 讨论(0)
提交回复
热议问题