Announcement Announcement Module
Collapse
No announcement yet.
Spring Quartz Fired twice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Quartz Fired twice

    Hi .. i am using spring + struts to make an application using Eclipse.

    i facing a problem with using spring quartz in tomcat.
    i follow example give by
    http://home.ustc.edu.cn/~lwp2003/boo.../html/114.html

    i am using simpletrigger.

    i found 1 problem is , when my project name is ROOT , it seem like the trigger will fired twice , if the project name not ROOT, this not going to be a problem.


    below is my code:
    applicationcontext.xml
    Code:
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        <bean id="job" class="org.springframework.scheduling.quartz.JobDetailBean">
            <property name="jobClass">
                <value>com.apress.prospring.ch14.quartz.MessageJob</value>
            </property>
            <property name="jobDataAsMap">
                <map>
                    <entry key="message">
                        <value>This is a message from the Spring configuration file!
                       </value>
                    </entry>
                </map>
            </property>
        </bean>
        
        <bean id="trigger" 
                    class="org.springframework.scheduling.quartz.SimpleTriggerBean">
            <property name="jobDetail">
                <ref local="job"/>
            </property>
            <property name="startDelay">
                <value>1000</value>
            </property>
            <property name="repeatInterval">
                <value>3000</value>
            </property>
        </bean>
        
        <bean id="schedulerFactory" 
                   class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref local="trigger"/>
                </list>
            </property>
        </bean>
    </beans>
    simplejob.java
    Code:
    package com.apress.prospring.ch14.quartz;
        
    import java.util.Map;
        
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
        
    public class MessageJob implements Job {
        
        public void execute(JobExecutionContext context)
                throws JobExecutionException {
            Map properties = context.getJobDetail().getJobDataMap();
        
            System.out.println("Previous Fire Time: "
                    + context.getPreviousFireTime());
            System.out.println("Current Fire Time: " + context.getFireTime());
            System.out.println("Next Fire Time: " + context.getNextFireTime());
        
            System.out.println(properties.get("message"));
        
            System.out.println("");
        }
    }

  • #2
    You should perhaps try to give your scheduler a unique name. (SchedulerFactoryBean.schedulerName)

    Comment


    • #3
      check your web.xml file

      I had the same trouble. In my ocasion the bug was in web.xml file. There were two defenitions of contextConfigLocation and of course it was the same. So I had deleted duplicate entry and it began work properly.

      I don't know if this post is still actual for you, but I think it could be helpfull for someone.

      Comment


      • #4
        Mikhail.spb, thank you very much for sharing this information.

        This solved the problem.

        Comment

        Working...
        X