[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Messages posted by: iamgrief  XML
Profile for iamgrief -> Messages posted by iamgrief [1]
Author Message
Yes, this is some kind of necroposting but I faced exactly the same issue today and spend a lot of time searching for the root cause. I found one, I cannot guarantee that you were experiencing the same, but still.

Anyway, the idea is pretty simple. I found the following code in org.quartz.core.QuartzScheduler:
Code:
     public Date scheduleJob(JobDetail jobDetail, Trigger trigger) throws SchedulerException {
         ...
         resources.getJobStore().storeJobAndTrigger(jobDetail, trig);
         notifySchedulerListenersJobAdded(jobDetail);
         notifySchedulerThread(trigger.getNextFireTime().getTime());
         notifySchedulerListenersSchduled(trigger);
 
         return ft;
     }
 

In case of database jobstore, the record should appear in the quartz_triggerz db table right after storeJobAndTrigger() being called.
So I set a breakpoint on the first notify and found that this is not true. The record appears later which means that the database transaction is not completed. That was the root cause in my case. I found a @Transactional annotation somewhere in the call chain. So the inner transaction created by jobStore was attached to the outer one and nobody from listeners and threads could get the data from the db when they were notified.

I would like to share the configuration of the quartz scheduler with the community, it works for me on latest versions of all dependent libraries:
Code:
            <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                 <property name="schedulerName" value="some_name"/> <!-- important to set, otherwise it will contain standard Object.toString() result with @ADDRESS part which will lead to inability to load jobs from the database between restarts since addresses change every time but the name is used to find jobs related to the current instance of scheduler -->
                 <property name="dataSource" ref="dataSource"/>
                 <property name="transactionManager" ref="transactionManager"/>
                 <property name="waitForJobsToCompleteOnShutdown" value="true"/> <!-- you might want another behavior -->
                 <property name="jobFactory">
                     <bean class="AutowiringSpringBeanJobFactory"/> <!-- this just handles @Autowired annotation for jobs with the help of AutowireCapableBeanFactory, I took it from https://gist.github.com/jeffsheets/5862630 -->
                 </property>
                 <property name="quartzProperties">
                     <map>
                         <entry key="org.quartz.jobStore.driverDelegateClass" value="org.quartz.impl.jdbcjobstore.PostgreSQLDelegate"/> <!-- for correct work with lobs -->
                     </map>
                 </property>
             </bean>
         </property>
 


You can use PGSimpleDataSource, PGPoolingDataSource, I used c3p0.ComboPooledDataSource with PGSimpleDataSource passed inside.
 
Profile for iamgrief -> Messages posted by iamgrief [1]
Go to:   
Powered by JForum 2.1.7 © JForum Team