Announcement Announcement Module
No announcement yet.
Issue with persisting Quartz job in mysql with SchedulerFactoryBean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with persisting Quartz job in mysql with SchedulerFactoryBean


    I am having an issue with saving Quartz jobs to MYSQL with quartz 2.1.3 and spring 3.1.1.

    I have a simple Quartz job and trigger defined in my spring file (config file is attached below). After my server (tomcat) starts up, I don't see the job and trigger in QUARTZ tables. In MYSQL log, I am seeing a rollback being sent right after the INSERT sql for QUARTZ tables. After some debugging, it looks like the rollback is sent by closeConnection in LocalDataSourceJobStore class. I have tried various configuration changes and just not able to change this behavior. Why does it not commit the changes?

    The followings are my config info. Thanks in advance.

    	         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">...</bean>
                     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">...</bean>
                     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    		  <property name="sessionFactory" ref="sessionFactory" />
                    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    		<property name="startupDelay" value="15" />
    		<property name="applicationContextSchedulerContextKey" value="applicationContext" />
    		<property name="schedulerName" value="myschedule" />
    		<property name="jobFactory" ref="springBeanJobFactory" />
    		<property name="dataSource" ref="dataSource" />
    		<property name="triggers">
                                    <ref bean="dummyTrigger" />
    		<property name="quartzProperties">
    				<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
    				<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
        <bean id="testMail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
          <property name="jobClass">
            <property name="name"><value>mail</value></property>
            <property name="group"><value>test</value></property>
        <bean id="dummyTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
          <property name="jobDetail">
            <ref bean="testMail"/>
          <property name="startDelay">
            <property name="repeatInterval">
            <property name="name"><value>trigger</value></property>
            <property name="group"><value>test</value></property>

  • #2
    ScheduleFactoryBean not persist Quartz jobs on MySQL 5.5+

    I did more debugging and the followings are the flow during server startup:

    1. ScheduleFactoryBean.afterPropertiesSet calls registerJobsAndTriggers during startup
    2. this.transactionManager.getTransaction(new DefaultTransactionDefinition())
    3. DataSourceUtils.doGetConnection(dataSource); (in LocalDataSourceJobStore class)
    4. INSERT triggers and job details with the connection from step 3
    5. DataSourceUtils.releaseConnection(con, this.dataSource); (in LocalDataSourceJobStore)
    6. this.transactionManager.commit(transactionStatus) (from step 1)
    7. commit() calls triggerBeforeCompletion (in AbstractPlatFormTransactionManager)
    8 triggerBeforeCompletion eventually calls connection.close() because referenceCount (in ConnectionHolder) is zero (changed from 1 to 0 by releaseConnection).
    9. connection.close triggers a ROLLBACK, as shown in the log on MySQL side.

    This config works fine on our existing server running MySQL 5.1.8 (our existing prod server), but does not work on any new installation with latest MySQL. I believe the reason is that MyISAM is the default engine prior to MySQL 5.5.5. MyISAM does not support transaction so the ROLLBACK from connection.close does not really do anything. But with the lastest MySQL, InnoDB is the default engine with support of transaction. connection.close actually rolls back any pending changes.

    I may be missing something here. Please help.