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

  • Quartz Job firing twice

    I posted this question in "Web" forum few days back but i think its more appropriate to put it in "Core Container" forum.

    I have configured quartz with spring and set a job to fire every 5 seconds. The job is fired every five seconds but it get fired twice after every fire second. Here is log of statment if put in my job detail class.

    Code:
    Executing job: DEFAULT.myJobDetail executing at Thu Mar 11 14:39:25 GMT+05:00 2010
    Executing job: DEFAULT.myJobDetail executing at Thu Mar 11 14:39:27 GMT+05:00 2010
    Executing job: DEFAULT.myJobDetail executing at Thu Mar 11 14:39:30 GMT+05:00 2010
    Executing job: DEFAULT.myJobDetail executing at Thu Mar 11 14:39:32 GMT+05:00 2010
    Executing job: DEFAULT.myJobDetail executing at Thu Mar 11 14:39:35 GMT+05:00 2010
    Executing job: DEFAULT.myJobDetail executing at Thu Mar 11 14:39:37 GMT+05:00 2010
    As you can see it fires at 25, 30, 35 but each time it fires twice.

    Here is my spring file. Also i am using ACEGI and SweetDevRia ajax library in my project.

    Code:
    <bean id="myobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
          <property name="jobClass" value="my.package.MyJob" />
          <property name="jobDataAsMap">
    	<map>
                  	<entry key="bean1" value-ref="myBean1" />   
              	             <entry key="bean2" value-ref="myBean2" /> 
                 </map>
           </property>				
    </bean>
    		
    <bean id="myTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
         <property name="jobDetail" ref="myJobDetail" />
         <property name="repeatInterval" value="5000" />
    </bean>
    		  
     <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
         <property name="triggers">
            <list> <ref bean="myTrigger" /> </list>
         </property>
     </bean>
    And my job class is:
    Code:
    Public class MyJob extends QuartzJobBean {
    
        public MyJob() {
        }
    
    
        public void executeInternal(JobExecutionContext context) throws JobExecutionException {
        	
    String jobName = context.getJobDetail().getFullName();
    System.out.println("Executing job: " + jobName + " executing at " + new Date());
    }
    }

  • #2
    i also noticed constructor of MyJob class is called every time the job fires. Should there be only one shared instance of this class in spring and it should be created everytime?

    Comment


    • #3
      My guess you are loading the configurationt wice, once with your ContextLoaderListener and once in the DispatcherServlet resulting in duplication. Check your config.

      Comment


      • #4
        Originally posted by Marten Deinum View Post
        My guess you are loading the configurationt wice, once with your ContextLoaderListener and once in the DispatcherServlet resulting in duplication. Check your config.
        Thanks Marten, This was exact problem.

        But why my jobclass is get instantiated every time job is called. Shouldn'd spring create it once only.

        Comment


        • #5
          No... A Job is created each time a trigger fires, hence you specify a jobClass and not an instance..

          Comment


          • #6
            okk...i need to dig more in how quartz job bean differ from normal spring beans. Normal beans are created once and then one isntance is shared across application until specified other way.

            thanks marten for clarifying things.

            Comment

            Working...
            X