Risks Caused by implementation of TimerFactoryBean by regular Scheduling in spring, timerfactorybean

Source: Internet
Author: User

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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.