Announcement Announcement Module
Collapse
No announcement yet.
Quartz job fires twice when manually starting job Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz job fires twice when manually starting job

    Hi Folks,

    I'm making this its own post rather than extending my previous one. I came across the SchedulerFactoryBean to handle manual job starting but I have a problem where when I start a job, it will fire twice, sometimes three times in quick succession before resuming its normal processing schedule. Here's what my configuration looks like:

    Code:
    <bean id="eleadTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
      	<property name="jobDetail" ref="eleadEngineJob"/>	
      	<property name="repeatInterval" value="10000"/>
      	<property name="startDelay" value="10000"/>
    </bean>
    	
    <bean id="mappointTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
     	<property name="jobDetail" ref="mappointEngineJob"/>
      	<property name="repeatInterval" value="60000"/>
     	<property name="startDelay" value="15000"/>
    </bean>
    	
    <bean id="eleadEngineJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    	
    	<property name="jobClass" value="com.mitsubishi.mmsa.service.offers.EleadEngineServiceImpl"/>
    	<property name="jobDataAsMap">
    		<map>
    			<entry key="offerBatchDedupDao" value-ref="offerBatchDedup"/>	
    			<entry key="adfXmlParseService" value-ref="adfParseService"/>	
    			<entry key="offerPostService" value-ref="offerPostService"/>	
    			<entry key="insertEleadXMLDao" value-ref="insertOfferXmlDao"/>	
    			<entry key="insertOfferLoggerDao" value-ref="offerLogger"/>	
    			<entry key="loggingStoredProc" value-ref="loggingDao"/>	
    		</map>
    	</property>
    </bean>
    	
    <bean id="mappointEngineJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    	
    	<property name="jobClass" value="com.mitsubishi.mmsa.service.offers.MapPointEngineServiceImpl"/>
    	<property name="jobDataAsMap">
    		<map>
    			<entry key="fillDealerDao" value-ref="fillDealerIdDao"/>
    			<entry key="mapPointService" value-ref="mapPointService"/>				
    			<entry key="fetchLimit" value="5"/>
    		</map>
    	</property>
    		
    </bean>
    	
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    	<property name="triggers">
    		<list>
    			<ref bean="eleadTrigger"/>
    			<ref bean="mappointTrigger"/>
    		</list>
    	</property>
            <property name="autoStartup" value="false"/>
    	<property name="waitForJobsToCompleteOnShutdown" value="true"/>
    </bean>
    And my "schedule manager" is a servlet that pulls the spring context in through its init method and gets access to the scheduler as such:

    Code:
    scheduler = (Scheduler)springCtx.getBean("scheduler");
    Then when a command is given to start the engine I do this:

    Code:
    scheduler.start();
    But each time I try this the job seems to fire quickly then settle into its routine. Has anyone had the problem before? Any solutions on how to solve it? Thanks.

  • #2
    The scheduler already is started, so you don't have to do it again (the SchedulerFactoryBean automatically starts the Scheduler).

    If you want to execute the job manually, you can use the triggerJob functions from the quartz scheduler itself.

    And have you thought about overlapping executions? If you don't want that to occur, you should set the statefull property on the JobDetailBean. What you also can do is placing a single thread in the Quartz ThreadPool.
    Last edited by Alarmnummer; Sep 17th, 2006, 03:11 AM.

    Comment


    • #3
      Thanks for the reply,

      Per your instruction I tried the following:

      Code:
      scheduler.triggerJob(engineJobName, Scheduler.DEFAULT_GROUP);
      and this seemed to have no effect. It seems like the scheduler is still not active. Both of my jobs use the default group as you can tell from the code, and they use the spring ids as the job names. Is there something else I'm missing?

      Thanks..

      Comment


      • #4
        Hi guys, sorry for the denseness here. I've been trying to get my scheduler to manually invoke a job when it has been set to autoStart = false. It was mentioned above that the scheduler is already started and that all I had to do was call myScheduler.triggerJob(myjobName, Scheduler.DEFAULT_GROUP) in order to begin the execution of my job. This just hasn't been working for me. The only way to get my jobs working is to actually call myScheduler.start() but this causes my original problem, the job executes in rapid sequence, twice, even three times, then resumes its normal schedule. If anyone has suggestions on how to get this working in a consistent manner, I'd appreciate it much, all the confiurations in the previous posting still apply. Thank you!

        Comment


        • #5
          Got it!

          Hey Guys,

          I got this figured out a little while ago. Thought I might show what I came up with for anyone looking. Bacically I have 2 scheduled jobs that get ran anywhere from every 10 seconds to 30 seconds. These engines as I call them are then managed by a separate servlet:

          spring config:
          Code:
          	<bean id="eleadTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
            		<property name="jobDetail" ref="eleadEngineJob"/>
            		<property name="repeatInterval" value="10000"/>
          	</bean>
          	
          	<bean id="mappointTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
            		<property name="jobDetail" ref="mappointEngineJob"/>
            		<property name="repeatInterval" value="12000"/>
          	</bean>
          	
          	<bean id="eleadEngineJob" class="org.springframework.scheduling.quartz.JobDetailBean">
          	
          		<property name="jobClass" value="com.mitsubishi.mmsa.service.offers.EleadEngineServiceImpl"/>
          		<property name="jobDataAsMap">
          			<map>
          				<entry key="offerBatchDedupDao" value-ref="offerBatchDedup"/>
          				<entry key="adfXmlParseService" value-ref="adfParseService"/>
          				<entry key="offerPostService" value-ref="offerPostService"/>
          				<entry key="insertEleadXMLDao" value-ref="insertOfferXmlDao"/>
          				<entry key="insertOfferLoggerDao" value-ref="offerLogger"/>	
          				<entry key="loggingStoredProc" value-ref="loggingDao"/>	
          			</map>
          		</property>
          	</bean>
          	
          	<bean id="mappointEngineJob" class="org.springframework.scheduling.quartz.JobDetailBean">
          	
          		<property name="jobClass" value="com.mitsubishi.mmsa.service.offers.MapPointEngineServiceImpl"/>
          		<property name="jobDataAsMap">
          			<map>
          				<entry key="fillDealerDao" value-ref="fillDealerIdDao"/>
          				<entry key="mapPointService" value-ref="mapPointService"/>				
          				<entry key="fetchLimit" value="5"/>
          			</map>
          		</property>
          	</bean>
          	
          	<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
          		<property name="triggers">
          			<list>
          				<ref bean="eleadTrigger"/>
          				<ref bean="mappointTrigger"/>
          			</list>
          		</property>
          		<property name="quartzProperties">
          			<props>
          				<prop key="org.quartz.threadPool.threadCount">1</prop>
          			</props>
          		</property>
          		<property name="autoStartup" value="false"/>
          		<property name="waitForJobsToCompleteOnShutdown" value="true"/>
          	</bean>
          Then in the init method of my EngineManagerServlet class:

          Code:
          	public void init() throws ServletException {
          		
          		springCtx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
          		scheduler = (Scheduler)springCtx.getBean("scheduler");
          		
          		try {
          			scheduler.pauseAll();			
          		} catch (SchedulerException e) {
          			e.printStackTrace();
          		}
          		
          	}
          I found that even if I configure the scheduler to autoStart=false, I had to pauseAll jobs. Then to start an engine:

          Code:
          scheduler.resumeJob(engineJobName, Scheduler.DEFAULT_GROUP);
          To stop:

          Code:
          scheduler.pauseJob(engineJobName, Scheduler.DEFAULT_GROUP);
          To change the fire interval of a trigger:

          Code:
          trigger.setRepeatInterval(newSleepValueInMillis);
          So altogether this has been working extremely well. My actual classes that represent the jobs are classes that implement StatefulJob. So thanks for the help on this, I can see a million uses in the future for this!!!

          Comment

          Working...
          X