About Spring when you use multiple Quatz profiles to configure a scheduled task, only one of the files is valid for the task

Source: Internet
Author: User

About Spring when you use multiple Quatz profiles to configure a scheduled task, only one of the files is valid for the taskProblem description

Work with spring and Quatz to implement timer triggering some scheduled tasks, originally written in a configuration file. After splitting the different business logic into two files, it was found that each time the spring container was started, only the scheduled tasks configured in one of the files were executed again, and the other did not.

Solution Solutions

The solution was found on StackOverflow through Google, but the reason was simple. In the case where multiple scheduler are configured in the Spring container, each scheduler must be given a name and ID, otherwise multiple scheduler configured with a singleton will overwrite each other, causing only one scheduler configuration to run.
So make the following changes to the configuration file:

<beans>    ......    前面关于执行类的定义这里省略    ......   <!-- Scheduler配置 如果将lazy-init=‘false‘那么容器启动就会执行调度程序,如果配置了多个,必须分配id,且每个Scheduler id不同 -->    <bean id="startQuertz" lazy-init="false" singleton="true"          class="org.springframework.scheduling.quartz.SchedulerFactoryBean">          <!--name也必须设置,保证各Scheduler之间不同即可-->        <property name="schedulerName" value="defaultScheduler"/>        <property name="triggers">            <list>                <ref bean="doTime"/>            </list>        </property>    </bean></beans>
Resources
    1. StackOverflow: "Using the schedulers in one Spring context"

About Spring when you use multiple Quatz profiles to configure a scheduled task, only one of the files is valid for the task

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.