Announcement Announcement Module
No announcement yet.
Quartz jobs are executed simultaniously in a cluster environment Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz jobs are executed simultaniously in a cluster environment

    I'm working with spring 3.1.2.RELEASE, quartz 1.8.6, MSSQL server and tomcat 7.x.
    I'm trying to run a simple task in a cluster of two tomcat nodes, and quartz seems to execute the job on both nodes simultaniously. I have a simple job which is scheduled to run every 10 seconds. I expect, that in a cluster environment, within any given interval of 10 seconds quartz is supposed to run the job only once, regardless of the node it chooses to execute the job. The actual behaviour I see is that the task is executed on both nodes, where the difference between one node's execution and another is much less than 10 seconds.

    Below is the following spring context I use:
    <context:component-scan base-package="org.samples.schedule" />

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="scheduleDataSource" />

    <jee:jndi-lookup id="scheduleDataSource" jndi-name="jdbc/ScheduleDataSource" />

    <context:annotation-config />

    <bean class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
    <property name="dataSource" ref="scheduleDataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="applicationContextSchedulerContextKey">
    <property name="triggers">
    <ref bean="simpleTrigger" />
    <property name="overwriteExistingJobs" value="true" />
    <property name="quartzProperties">
    <prop key="org.quartz.scheduler.instanceName">Scheduler</prop>
    <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
    <prop key="org.quartz.jobStore.misfireThreshold">1000</prop>
    <prop key="org.quartz.jobStore.clusterCheckinInterval">1 000</prop>
    <prop key="org.quartz.jobStore.class">
    <prop key="org.quartz.jobStore.driverDelegateClass">org. quartz.impl.jdbcjobstore.MSSQLDelegate
    <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
    <prop key="org.quartz.jobStore.isClustered">true</prop>
    <prop key="org.quartz.threadPool.class">
    <prop key="org.quartz.threadPool.threadCount">10</prop>
    <prop key="org.quartz.threadPool.threadPriority">5</prop>

    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
    <!-- see the example of method invoking job above -->
    <property name="jobDetail" ref="loggerJob" />
    <property name="repeatInterval" value="10000" />

    <bean name="loggerJob" class="org.springframework.scheduling.quartz.JobDe tailBean">
    <property name="jobClass" value="org.samples.schedule.BatchJobWrapper" />
    <property name="jobDataAsMap">
    <entry key="jobName" value="logTask" />

    I simply deploy the same application on two tomcat instances and start the both.
    Any ideas?


  • #2
    Same behaviour is observed when using org.springframework.scheduling.quartz.CronTriggerB ean instead of a simple org.springframework.scheduling.quartz.SimpleTrigge rBean:

    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
    <property name="jobDetail" ref="loggerJob" />
    <property name="cronExpression" value="0/10 * * * * ?" />

    Tasks just get executed on both nodes same time...

    Last edited by jacobo; Nov 19th, 2012, 04:23 AM.


    • #3
      This isn't a batch question but a Quartz question...moving to Core Spring forum.