Quartz + Spring double execution on startup

Posted by Osy on Stack Overflow See other posts from Stack Overflow or by Osy
Published on 2013-11-04T21:50:48Z Indexed on 2013/11/04 21:53 UTC
Read the original article Hit count: 491

I have Quartz 2.2.1 and Spring 3.2.2. app on Eclipse Juno

This is my bean configuration:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- Spring Quartz -->

<bean id="checkAndRouteDocumentsTask" class="net.tce.task.support.CheckAndRouteDocumentsTask" />

<bean name="checkAndRouteDocumentsJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">

    <property name="jobClass" value="net.tce.task.support.CheckAndRouteDocumentsJob" />
    <property name="jobDataAsMap">
        <map>
            <entry key="checkAndRouteDocumentsTask" value-ref="checkAndRouteDocumentsTask" />
        </map>
    </property>
    <property name="durability" value="true" />

</bean>

<!-- Simple Trigger, run every 30 seconds -->
<bean id="checkAndRouteDocumentsTaskTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">

    <property name="jobDetail" ref="checkAndRouteDocumentsJob" />
    <property name="repeatInterval" value="30000" />
    <property name="startDelay" value="15000" />

</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="jobDetails">
        <list>
            <ref bean="checkAndRouteDocumentsJob" />
        </list>
    </property>

    <property name="triggers">
        <list>
            <ref bean="checkAndRouteDocumentsTaskTrigger" />
        </list>
    </property>
</bean>

My mvc spring servlet config:

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">  
    <bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    </bean>
    <mvc:annotation-driven />
    <context:annotation-config />
    <context:component-scan base-package="net.tce" />
    <import resource="spring-quartz.xml"/>  
</beans>

My problem is that always when startup my application, Quartz creates two jobs at the same time. My job must be execute every 30 seconds:

INFO: Starting TASK on Mon Nov 04 15:36:46 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:36:46 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:16 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:16 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:46 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:46 CST 2013...

Thanks for your help.

© Stack Overflow or respective owner

Related posts about spring-mvc

Related posts about quartz-scheduler