5 Replies Latest reply on Oct 16, 2007 12:51 PM by Michael Yuan

    Quartz - persisting timers on the database problem.

    raffaele camanzo Newbie

      Hi all,

      I'm using Quartz in my application (I do not use EJB timers because Quartz seems to be more flexible and able to support clustering) and the Seam integration works very well if I do not re-start my AS.

      I've configured Quartz through the seam.quartz.properties as follows:

      #============================================================================
      # Configure Main Scheduler Properties
      #============================================================================
      
      org.quartz.scheduler.instanceName Sched1
      org.quartz.scheduler.instanceId AUTO
      org.quartz.scheduler.rmi.export false
      org.quartz.scheduler.rmi.proxy false
      
      #============================================================================
      # Configure ThreadPool
      #============================================================================
      
      org.quartz.threadPool.class org.quartz.simpl.SimpleThreadPool
      org.quartz.threadPool.threadCount 3
      
      #============================================================================
      # Configure JobStore
      #============================================================================
      
      org.quartz.jobStore.misfireThreshold 60000
      
      org.quartz.jobStore.class org.quartz.impl.jdbcjobstore.JobStoreTX
      org.quartz.jobStore.driverDelegateClass org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
      org.quartz.jobStore.useProperties false
      org.quartz.jobStore.dataSource flashDS
      org.quartz.jobStore.tablePrefix QRTZ_
      
      #============================================================================
      # Configure Datasources
      #============================================================================
      
      org.quartz.dataSource.flashDS.jndiURL jdbc/FlashDB
      
      


      and created the Quartz tables on my Oracle DB.

      No problem at deploy time, no problem at run-time, but the tables are empty and after a re-start no timer executes.

      Does Seam control correctly the Quartz DB persistence?
      Am I doing something wrong? Something missing?

      Help Appreciated.

      Regards,
      Raffaele Camanzo



        • 1. Re: Quartz - persisting timers on the database problem.
          raffaele camanzo Newbie

          I tried to go deeper in the problem and found these lines in the server.log:

          2007-10-16 15:26:44,810 INFO [org.jboss.seam.contexts.Contexts] starting up: org.jboss.seam.async.dispatcher
          2007-10-16 15:26:44,977 INFO [org.jboss.seam.async.QuartzDispatcher] No seam.quartz.properties file. Use in-memory job store.
          2007-10-16 15:26:45,061 INFO [org.quartz.simpl.SimpleThreadPool] Job execution threads will use class loader of thread: main
          2007-10-16 15:26:45,090 INFO [org.quartz.core.QuartzScheduler] Quartz Scheduler v.1.6.0 created.
          2007-10-16 15:26:45,093 INFO [org.quartz.simpl.RAMJobStore] RAMJobStore initialized.
          2007-10-16 15:26:45,094 INFO [org.quartz.impl.StdSchedulerFactory] Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource
           file in Quartz package: 'quartz.properties'
          2007-10-16 15:26:45,094 INFO [org.quartz.impl.StdSchedulerFactory] Quartz scheduler version: 1.6.0
          2007-10-16 15:26:45,097 INFO [org.quartz.core.QuartzScheduler] Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
          2007-10-16 15:26:45,097 INFO [org.jboss.seam.async.QuartzDispatcher] The QuartzDispatcher has started
          


          But the file exists and seems to be in the right place (the root of the jar); I tried also in the root of the ear and of the war but the Dispatcher says always the same thing.

          I tried to download the latest version from the CVS and added some prints around the root of the problem (getResourceAsStream("/seam.quartz.properties")) but with the current CVS version Seam prints nothing at all.

          Any suggestion?

          Regards,
          Raffaele Camanzo



          • 2. Re: Quartz - persisting timers on the database problem.
            raffaele camanzo Newbie

            Deeper, deeper, deeper... Found and solved.

            the problem:

            from the QuartzDispatcher.java:

            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/seam.quartz.properties");
            


            Seam does not recognize my seam.quartz.properties.

            I've changed it in:
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("seam.quartz.properties");
            


            and everything works great (if you use a Oracle DB remember to download the latest Quartz distribution and include the quartz-oracle.jar in your app).

            It seems to be a bug (no need to add the initial slash), indeed, searching for the seam.properties file in the Seam source code (seam.properties and seam.quartz.properties are in the same position and loaded in the same way) I found this:

            from Initialization.java
            ...
             private void scanForComponents()
             {
             ComponentScanner[] scanners = {
             new ComponentScanner("seam.properties"),
             new ComponentScanner("META-INF/seam.properties"),
             new ComponentScanner("META-INF/components.xml")
             };
            ...
            


            from ComponentScanner.java
            ...
             public ComponentScanner(String resourceName)
             {
             super(resourceName);
             }
            ...
            


            from Scanner.java
            ...
             public Scanner(String resourceName)
             {
             this( resourceName, Thread.currentThread().getContextClassLoader() );
             }
            ...
             protected void scan()
             {
             Set<String> paths = new HashSet<String>();
             if (resourceName==null)
             {
             for ( URL url: getURLsFromClassLoader() )
             {
             String urlPath = url.getFile();
             if ( urlPath.endsWith("/") )
             {
             urlPath = urlPath.substring( 0, urlPath.length()-1 );
             }
             paths.add( urlPath );
             }
             }
             else
             {
             try
             {
             Enumeration<URL> urlEnum = classLoader.getResources(resourceName);
            ...
            


            I don't know if this needs a Jira issue or if I'm wrong, then, it would be great if one of the Seam developers can have a glance at this.

            Regards,
            Raffaele Camanzo





            • 3. Re: Quartz - persisting timers on the database problem.
              Michael Yuan Newbie

              Thanks Raffaele! I will make change you suggested.

              But just curious, why would this wipe out your quartz tables? I thought that your app would not have worked with the oracle db if the seam.quartz.properties is not found ...

              Or was the tables never generated to begin with and you have been using in-memory job store all along?

              Thanks
              Michael

              • 4. Re: Quartz - persisting timers on the database problem.
                raffaele camanzo Newbie

                Hi Michael,

                thank you for your super-fast reply!

                About your question: obviously using RAM job store there was no access to the Oracle DB and then my tables were empty, never written, never wiped out (Quartz works properly with RAM job store, but restarting jBoss AS causes the loss of all the timers);
                probably the misunderstanding was caused by my not-as-good-as-should-be-english ;)

                Regards,
                Raffaele Camanzo

                • 5. Re: Quartz - persisting timers on the database problem.
                  Michael Yuan Newbie

                  Hi Raffaele,

                  Thanks for the update. I made the change in CVS. Please let us know if you have other issues / suggestions with Quartz in Seam!

                  cheers
                  Michael