3 Replies Latest reply on Oct 15, 2010 6:31 PM by rwfuller

    Issue with Seam timer not firing

    rwfuller

      We have created a timer with the following code to handle a basic job queue.  The job queue is database driven and is dependent on a Timer to check to see if any jobs are available.


      This is how the timers are created.


         @Observer( "org.jboss.seam.postInitialization" )
          public void initTheTimers() {
              Events.instance().raiseEvent( "jobs.flush" );
              Events.instance().raiseTimedEvent( "jobs.checkInvalid", new TimerSchedule( 0L, 5 * ONE_MINUTE ) );
              Events.instance().raiseTimedEvent( "jobs.check", new TimerSchedule( ONE_MINUTE, ONE_MINUTE / 2 ) );
          }



      And after one minute, this method gets called every 30 seconds.


         private static volatile boolean checkingForJobsCurrently = false;
      
          @Observer( { "jobs.check" } )
          @Asynchronous
          @Transactional( TransactionPropagationType.REQUIRED )
          public void checkForNodeJobs() {
              LOG.info( "Checking for new jobs..." );
              
              if ( !checkingForJobsCurrently ) {
                  checkingForJobsCurrently = true;
      
                  try {
                      //
                      // Assign jobs
                      //
                  } finally {
                      checkingForJobsCurrently = false;
                  }
              }
      
              LOG.info( "Finished checking for new jobs." );
          }
      



      If a user changes a particular item in our UI which requires what could be some complicated calculations, we create what we call a Job.  This job is then assigned a node to do the calculation.


      The problem is when we put ten or more jobs in the database, the timer stops firing every 30 seconds.  Sometimes it will not fire for 10 or longer minutes.  Once it does fire, then everything starts working.


      Is there a way to debug why a timer does not get fired?

        • 1. Re: Issue with Seam timer not firing
          kapitanpetko

          Not exactly clear what you are trying to do, but in short: don't reinvent the wheel, use Quartz. That gives you the option of DB persisted jobs, retrying, re-scheduling and detailed debug logs and more.


          • 2. Re: Issue with Seam timer not firing
            rwfuller

            Before your post I already started going down the Quartz road just to see if it was an ejbTimer issue.  Quartz was fairly easy to plugin and I did not have to change any code, just components.xml and add a property file.  Using Quartz, I started seeing the same thing and worse.  I turned Seam logging to DEBUG and noticed that Seam was trying to inject Events and just hung.


            The problem ended up being not enough threads for the timer.  We increased Quartz to use 20 threads, and everything started working as expected.

            • 3. Re: Issue with Seam timer not firing
              rwfuller

              The sad part of debugging this was there was not a single exception.