[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 
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:
     public Date scheduleJob(JobDetail jobDetail, Trigger trigger) throws SchedulerException {
         resources.getJobStore().storeJobAndTrigger(jobDetail, trig);
         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:
            <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 name="quartzProperties">
                         <entry key="org.quartz.jobStore.driverDelegateClass" value="org.quartz.impl.jdbcjobstore.PostgreSQLDelegate"/> <!-- for correct work with lobs -->

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