Spring - 如何设置ScheduledTimerTask的周期间隔?

时间:2014-01-16 14:13:50

标签: java multithreading spring spring-mvc timer

我的xml配置将是,

    <bean id="producer" class="com.pointel.T_Server.service.Producer" />

<bean id="timerTaskFactoryBean" class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
    <property name="targetObject" ref="producer"></property>
    <property name="targetMethod" value="executeListener"></property>
</bean>



    <bean id="timerTask" class="org.springframework.scheduling.timer.ScheduledTimerTask" singleton="true">
        <property name="timerTask" ref="timerTaskFactoryBean"></property>
        <property name="delay" value="5000"></property>
        <property name="period" value="60000"></property>
    </bean>



    <bean class="org.springframework.scheduling.timer.TimerFactoryBean">
        <property name="scheduledTimerTasks">
            <list>
                <ref local="timerTask"></ref>
            </list>
        </property>
    </bean>

spring控制器中,我将句号更新为

org.springframework.scheduling.timer.ScheduledTimerTask timer = (org.springframework.scheduling.timer.ScheduledTimerTask)xmlWebApplicationContext.getBean("timerTask");
System.out.println("Period Before :"+timer.getPeriod()); // prints 60000
timer.setPeriod(5000);
System.out.println("Delay After :"+timer.getPeriod()); // prints 5000

但是执行目标方法不会影响时间间隔。

它仅再次运行60秒。

为什么我的更新不会影响间隔?

0 个答案:

没有答案