2 Replies Latest reply on Jun 6, 2006 10:32 AM by tsar_bomba

    Timer service won't work reliably...

      I've been working w/ some examples in the new Enterprise JavaBeans 3.0 book and I created a simple timer to run every 10 minutes and check for data integrity.

      When JBoss decides to let it run, it works great. However it doesn't always work when I deploy the app....sometimes I get this exception:

      11:45:20,480 ERROR [TimerServiceImpl] Cannot create txtimer
      java.lang.IllegalStateException: Unable to persist timer
       at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:126)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy22.insertTimer(Unknown Source)
       at org.jboss.ejb.txtimer.TimerServiceImpl.createTimer(TimerServiceImpl.java:256)
       at org.jboss.ejb.txtimer.TimerServiceImpl.createTimer(TimerServiceImpl.java:202)
       at com.agribeef.abcommerce.service.PollingServiceBean.init(PollingServiceBean.java:32)
      


      My timer looks like this:

      @Stateless
      public class PollingServiceBean implements PollingService
      {
       @Resource
       private TimerService ts;
      
       private static final int timeout = 1000 * 60 * 10; //ten minutes
      
       public PollingServiceBean()
       {
       }
      
       public void init()
       {
       if (ts.getTimers().size() == 0)
       {
       this.ts.createTimer(5000, timeout, "pollServicesTimer");
       }
       }
      
       @Timeout
       public void startService(Timer timer)
       {
       try
       {
       //do something here....
       }
       catch (Exception exp)
       {
       // TODO Auto-generated catch block
       exp.printStackTrace();
       }
       }
      }
      


      First of all, what is "txtimer", I haven't named my timer that?

      It runs sometimes and runs well...and then I re-deploy the same code and get the exception above...am I doing something wrong or is there a known problem?

      Thanks!

        • 1. Re: Timer service won't work reliably...

          I'm sorry, I realize I just missed probably the most important part of the exception, the root cause!

          It looks like HSQLDB doesn't like that I'm trying to start a timer w/ the same name.

          Caused by: java.sql.SQLException: Unique constraint violation: in statement [insert into TIMERS (TIMERID,TARGETID,INITIALDATE,TIMERINTERVAL,INSTANCEPK,INFO) values (?,?,?,?,?,?)]
           at org.hsqldb.jdbc.Util.throwError(Unknown Source)
           at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
           at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.executeUpdate(CachedPreparedStatement.java:95)
           at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251)
           at org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.insertTimer(GeneralPurposeDatabasePersistencePlugin.java:186)
           at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:122)
           ... 138 more
          


          This seems strange to me, I can't redeploy my app or new timers will be inserted w/ the same names...and my timers will blow up!

          The book mentions nothing about deleting them or anything of that nature - what can I do?

          • 2. Re: Timer service won't work reliably...

            So I narrowed this down to a single scenario...it's still not sufficient for me in production and I'm hoping there's at *least* a work-around.

            If I restart JBoss the Timer Service crashes w/ the aforementioned exception...however if I re-deploy the app the timer starts - so far on every test.

            What can I do?

            I put a file named "jboss.xml" in my ejb project's META-INF folder that looks like this but I'm not even sure I've done that much right:

            <?xml version="1.0" encoding="UTF-8"?>
            <jboss>
             <timer-persistence>false</timer-persistence>
            </jboss>
            


            Any help would be greatly appreciated, thanks!