Announcement Announcement Module
Collapse
No announcement yet.
Trouble getting quartz to work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble getting quartz to work

    Hi all,

    I'm trying to get Spring and Quartz working, specifically to create triggers programmatically in response to events in my application.

    A simple test with a manually created Quartz scheduler and programmatically created JobDetails and Triggers works fine.

    Another simple test with a Spring created scheduler, with JobDetails and Triggers also defined in the application context (ala Spring reference) also works just fine.

    However, using a Spring created scheduler with a programmatically created Trigger and JobDetail does not work. After trying for the last day to get this working, I'm beat. Any ideas of what I've got wrong are much appreciated:

    Thanks,

    L.

    (Sorry about some mangled code etc., trying to evade the forum thinking I'm posting URLs).

    Using Spring 2-5-5 and Quartz 1-6-1.

    applicationContext.xml
    Code:
    <bean id="scheduler" class="org-springframework-scheduling-quartz-SchedulerFactoryBean">   
    </bean>
    Note: I have a dataSource and transactionManager defined elsewhere, I've tried setting these manually. Also tried just about all available properties, as well as using a RAM job store.

    MyTest.java
    Code:
    private Scheduler scheduler;
    
    <snip>
    
    JobDetail jobDetail = new JobDetail("dumbJob", null, DumbJob.class);
            
    Trigger t = TriggerUtils.makeSecondlyTrigger("dumbTrigger");
            
    System-out-println("Scheduling dumb job...");
    
    scheduler.scheduleJob(jobDetail, t);
            
    for (int i = 0; i < 6; i++) {
        Thread.sleep(1000);
    }
    Using a scheduler created according to the Quartz tutorial instead of the autowired one works fine. "DumbJob" just logs a single line each run, which appear in the output when using either a manually configured scheduler or a Spring configured JobDetail and Trigger.

    Output in next post.

  • #2
    Output:
    Code:
        [junit] 2008-11-20 10:32:46,949 INFO - SchedulerSignalerImpl-<init>(63) | Initialized Scheduler Signaller of type: class org-quartz-core-SchedulerSignalerImpl
        [junit] 2008-11-20 10:32:46,951 INFO - QuartzScheduler-<init>(215) | Quartz Scheduler v-1-6-1 created-                                                        
        [junit] 2008-11-20 10:32:46,977 DEBUG - DBSemaphore-obtainLock(106) | Lock 'TRIGGER_ACCESS' is desired by: main                                               
        [junit] 2008-11-20 10:32:46,989 DEBUG - StdRowLockSemaphore-executeSQL(88) | Lock 'TRIGGER_ACCESS' is being obtained: main                                    
        [junit] 2008-11-20 10:32:46,990 DEBUG - DBSemaphore-obtainLock(115) | Lock 'TRIGGER_ACCESS' given to: main                                                    
        [junit] 2008-11-20 10:32:46,992 DEBUG - DBSemaphore-releaseLock(142) | Lock 'TRIGGER_ACCESS' returned by: main                                                
        [junit] 2008-11-20 10:32:46,993 INFO - StdSchedulerFactory-instantiate(1224) | Quartz scheduler 'QuartzScheduler' initialized from an externally provided properties instance-
        [junit] 2008-11-20 10:32:46,994 INFO - StdSchedulerFactory-instantiate(1228) | Quartz scheduler version: 1-6-1                                                                
        [junit] 2008-11-20 10:32:46,994 INFO - QuartzScheduler-setJobFactory(2094) | JobFactory set to: [email protected]             
        [junit] 2008-11-20 10:32:47,114 DEBUG - DBSemaphore-obtainLock(106) | Lock 'TRIGGER_ACCESS' is desired by: main                                                               
        [junit] 2008-11-20 10:32:47,115 DEBUG - StdRowLockSemaphore-executeSQL(88) | Lock 'TRIGGER_ACCESS' is being obtained: main                                                    
        [junit] 2008-11-20 10:32:47,116 DEBUG - DBSemaphore-obtainLock(115) | Lock 'TRIGGER_ACCESS' given to: main                                                                    
        [junit] 2008-11-20 10:32:47,120 DEBUG - DBSemaphore-releaseLock(142) | Lock 'TRIGGER_ACCESS' returned by: main                                                                
        [junit] 2008-11-20 10:32:47,127 INFO - QuartzScheduler-start(461) | Scheduler QuartzScheduler_$_NON_CLUSTERED started-                                                        
        [junit] 2008-11-20 10:32:47,137 DEBUG - DBSemaphore-obtainLock(106) | Lock 'TRIGGER_ACCESS' is desired by: QuartzScheduler_QuartzSchedulerThread                              
        [junit] 2008-11-20 10:32:47,208 DEBUG - StdRowLockSemaphore-executeSQL(88) | Lock 'TRIGGER_ACCESS' is being obtained: QuartzScheduler_QuartzSchedulerThread                   
        [junit] 2008-11-20 10:32:47,209 DEBUG - DBSemaphore-obtainLock(115) | Lock 'TRIGGER_ACCESS' given to: QuartzScheduler_QuartzSchedulerThread                                   
        [junit] 2008-11-20 10:32:47,210 DEBUG - DBSemaphore-releaseLock(142) | Lock 'TRIGGER_ACCESS' returned by: QuartzScheduler_QuartzSchedulerThread                               
        [junit] 2008-11-20 10:32:48,302 INFO - SimpleThreadPool-initialize(258) | Job execution threads will use class loader of thread: main                                         
        [junit] 2008-11-20 10:32:48,460 INFO - SchedulerSignalerImpl-<init>(63) | Initialized Scheduler Signaller of type: class org-quartz-core-SchedulerSignalerImpl                
        [junit] 2008-11-20 10:32:48,460 INFO - QuartzScheduler-<init>(215) | Quartz Scheduler v-1-6-1 created-
        [junit] 2008-11-20 10:32:48,461 INFO - RAMJobStore-initialize(141) | RAMJobStore initialized-
        [junit] 2008-11-20 10:32:48,461 INFO - StdSchedulerFactory-instantiate(1224) | Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz-properties'
        [junit] 2008-11-20 10:32:48,461 INFO - StdSchedulerFactory-instantiate(1228) | Quartz scheduler version: 1-6-1
        [junit] 2008-11-20 10:32:48,461 INFO - QuartzScheduler-start(461) | Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started-
        [junit] Scheduling dumb job
        [junit] 2008-11-20 10:32:48,471 DEBUG - DBSemaphore-obtainLock(106) | Lock 'TRIGGER_ACCESS' is desired by: main
        [junit] 2008-11-20 10:32:48,472 DEBUG - StdRowLockSemaphore-executeSQL(88) | Lock 'TRIGGER_ACCESS' is being obtained: main
        [junit] 2008-11-20 10:32:48,473 DEBUG - DBSemaphore-obtainLock(115) | Lock 'TRIGGER_ACCESS' given to: main
        [junit] 2008-11-20 10:32:48,498 DEBUG - DBSemaphore-releaseLock(142) | Lock 'TRIGGER_ACCESS' returned by: main
        [junit] 2008-11-20 10:32:48,507 DEBUG - DBSemaphore-obtainLock(106) | Lock 'TRIGGER_ACCESS' is desired by: QuartzScheduler_QuartzSchedulerThread
        [junit] 2008-11-20 10:32:48,507 DEBUG - StdRowLockSemaphore-executeSQL(88) | Lock 'TRIGGER_ACCESS' is being obtained: QuartzScheduler_QuartzSchedulerThread
        [junit] 2008-11-20 10:32:54,503 DEBUG - DBSemaphore-obtainLock(115) | Lock 'TRIGGER_ACCESS' given to: QuartzScheduler_QuartzSchedulerThread
        [junit] 2008-11-20 10:32:54,504 DEBUG - DBSemaphore-releaseLock(142) | Lock 'TRIGGER_ACCESS' returned by: QuartzScheduler_QuartzSchedulerThread

    Comment


    • #3
      With some more logging, I've found the test method is throwing an exception somewhere, somehow:

      Code:
          [junit] 2008-11-20 13:59:42,850 DEBUG - SpringMethodRoadie.runTestMethod(256) | Test method [public void com.test.DumbJobTest.testDumbJob()] threw exception: null
      However trying to catch this exception leads to no results, which is confusing me. Is the exception being thrown in another thread? Is there any way to find the stack trace of this exception?

      Edit: After reading the source for SpringMethodRoadie, I'm pretty sure this line isn't a problem. It just logs this all the time, whether an exception is thrown or not.
      Last edited by ltmon; Nov 19th, 2008, 11:10 PM.

      Comment


      • #4
        Took me a while, but I've worked it out.

        Simply the fact that the way my test cases were set up, there was no transaction around the scheduling. Spring managed Schedulers require a transaction, whereas the manually created Scheduler does not.

        Ta,

        L.

        Comment


        • #5
          I'm late to this party, but trying to do the same thing.

          Wondering if you could share an example of surrounding your scheduler with a transaction, and perhaps the necessary confguration.

          Thanks

          Comment

          Working...
          X