Risks Caused by implementation of TimerFactoryBean by regular Scheduling in spring, timerfactorybean
An old project in the hand, where the scheduling task implemented by TimerFactoryBean is used. it is generally implemented in spring quartz, which is rare. this is because there are few rare materials. In order to confirm whether two scheduling tasks will be executed concurrently, we also carefully read the source code, which uses the jdk Timer implementation. that is, it does not start the next task because the previous task is not executed.
This TimerFactoryBean implements scheduling by introducing ScheduledTimerTask. The general configuration is as follows:
<bean id="myTask" class="xx.xx.MyTask" ><bean id="scheduleTask1" class="org.springframework.scheduling.timer.ScheduledTimerTask"> <property name="delay" value="10000" /> <property name="period" value="10000" /> <property name="timerTask"> <ref local="myTask" /> </property></bean><bean id="timerFactoryBean" class="org.springframework.scheduling.timer.TimerFactoryBean"> <property name="scheduledTimerTasks"> <list> <ref bean="scheduleTask1" /> </list> </property> </bean>
Then, if it runs stably all the time, it's a pity that this scheduling task often crashes and disappears .. the first impression is that no exception is caught, causing the program to exit due to an error, and then found that the custom code MyTask has caught the entire segment. then we also considered thread deadlocks and checked the stack information.
Later, I became more and more aware that there was a problem with this implementation. Then I tested the spring Z Implementation of spring and threw an uncaptured exception. Then I found that spring quartz can continue to execute the next task, the TimerFactoryBean has crashed .. it is estimated that the exception capture of this implementation is not good. due to various reasons, it will directly cause the entire scheduling task to die ..
Conclusion: The implementation of TimerFactoryBean is flawed. Therefore, we recommend that you use spring quartz to schedule tasks...