2 Replies Latest reply on Jan 31, 2006 1:13 AM by flashwindcn

    MDB Timer problem on jboss 4.0.3

    flashwindcn Newbie

      i get some error message:

      2006-01-25 11:46:30,586 ERROR [org.jboss.ejb.txtimer.TimerServiceImpl] Cannot create txtimer
      java.lang.IllegalStateException: Unable to persist timer
      at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:138)
      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:324)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
      at org.jboss.mx.util.JMXInvocationHandler.invoke(JMXInvocationHandler.java:273)
      at $Proxy82.insertTimer(Unknown Source)
      at org.jboss.ejb.txtimer.TimerServiceImpl.createTimer(TimerServiceImpl.java:212)
      at org.jboss.ejb.txtimer.TimerServiceImpl.createTimer(TimerServiceImpl.java:178)
      at org.jboss.ejb.MessageDrivenEnterpriseContext$TimerServiceWrapper.createTimer(MessageDrivenEnterpriseContext.java:253)
      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:324)
      at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
      at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.java:475)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
      at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:101)
      at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
      at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:94)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenContainer.java:389)
      at org.jboss.ejb.Container.invoke(Container.java:873)
      at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvoker.java:1077)
      at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onMessage(JMSContainerInvoker.java:1379)
      at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:256)
      at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:904)
      at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:160)
      at org.jboss.mq.SpySession.run(SpySession.java:333)
      at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:180)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
      at java.lang.Thread.run(Thread.java:534)
      Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Violation of PRIMARY KEY constraint 'TIMERS_PK'. Cannot insert duplicate key in object 'TIMERS'.
      at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
      at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
      at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
      at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
      at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
      at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
      at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
      at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
      at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
      at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
      at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
      at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
      at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
      at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:227)
      at org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.insertTimer(GeneralPurposeDatabasePersistencePlugin.java:161)
      at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:134)

      public class MailMDBBean
       implements MessageDrivenBean,
       MessageListener, TimedObject
      {
      
      
       private MessageDrivenContext messageContext = null;
      
      
      
      
      
       public void ejbCreate()
       {
      
      
       }
      
      
       public void ejbRemove() throws EJBException
       {
      
       }
      
      
      
       public void setMessageDrivenContext(MessageDrivenContext ctx)
       throws EJBException
       {
       messageContext = ctx;
       }
      
      
      
      
      
       public void onMessage(Message msg)
       {
      
      
       final ObjectMessage message = (ObjectMessage) msg;
      
       try
       {
       final Object obj = message.getObject();
      
       if (obj instanceof MailDTO)
       {
       final MailDTO mailDTO = (MailDTO) obj;
      
       final String sendNum = message.getStringProperty("SendNum");
       final String sendTimeStr = message.getStringProperty("FirstSendTime");
       final String retryTimeStr = message.getStringProperty("RetryTime");
      
       // Start the reply timer
       initTimer(message);
      
       }
       }
       catch (JMSException jmse)
       {
      
       }
      
      
       }
      
      
      
       private void initTimer(ObjectMessage message)
       {
      
      
       try
       {
       final String sendTimeStr = message.getStringProperty("FirstSendTime");
       final Date oldDate = new Date(new Long(sendTimeStr).longValue());
      
       final GregorianCalendar newCalendar = new GregorianCalendar();
       newCalendar.setTime(oldDate);
      
       final String retryTimeStr = message.getStringProperty("RetryTime");
      
       final int retryTimeInt = new Integer(retryTimeStr).intValue();
      
       Integer limitSec = new Integer(10);
      
       newCalendar.add(Calendar.SECOND, limitSec.intValue());
      
      
       Date first = newCalendar.getTime();
      
      
      
       ReplyInfo info = new ReplyInfo(message, first);
      
       final Object obj = message.getObject();
       final MailDTO mailDTO = (MailDTO) obj;
      
       TimerService ts = messageContext.getTimerService();
      
      
       Timer timer = ts.createTimer(first, info);
      
       }
       catch (Exception e)
       {
      
       }
       return;
       }
      
      
       static class ReplyInfo implements Serializable
       {
      
       Message message;
       private Date first;
      
      
       ReplyInfo(Message message, Date firstt)
       {
       this.message = message;
       this.first = first;
       }
      
       }
      
      
       public void ejbTimeout(Timer timer)
       {
      
       ReplyInfo info = (ReplyInfo) timer.getInfo();
      
      
      
       try
       {
      
       Message msg = info.message;
      
       final ObjectMessage message = (ObjectMessage) msg;
      
       final Object obj = message.getObject();
      
       if (obj instanceof MailDTO)
       {
       final MailDTO mailDTO = (MailDTO) obj;
      
      
       timer.cancel();
       }
      
       }
       catch(Exception e)
       {
      
       }
       }
      
      
      }
      


      what's wrong?

        • 1. Re: MDB Timer problem on jboss 4.0.3
          Frank Langelage Master

          Timers are persisted in a table "timers" in the DefaultDS per default.
          This may have been changed in deploy/ejb-deployer.xml at your side.
          The primary key contains 2 fields: timerid and targetid.
          For my app there are two times defined.
          timerid 1
          targetid [target=jboss.j2ee:jndiName=mbi2e-lafr-sb150-ipc/MessageEraser,service=EJB]
          timerid 2
          targetid [target=jboss.j2ee:jndiName=mbi2e-lafr-sb150-ipc/MessageObserver,service=EJB]

          Do you have entries in that table when all apps are undeployed or jboss is down? Delete them once.

          Using jboss-4.0.4RC1 here takes care of existing entries. The timer entries stay in the database on shutdown and are reused on startup. But there have been some modifications between 4.0.3 and 4.0.4 concerning the timer persistence handling.

          • 2. Re: MDB Timer problem on jboss 4.0.3
            flashwindcn Newbie

            Thanks for you reply! DatabasePersistencePolicy always occur error. i don't why, now i use NoopPersistencePolicy for the timer

            ejb-deployer.xml

            <!-- A persistence policy that does not persist the timer-->



            <!-- A persistence policy that persistes timers to a database


            <depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=DefaultDS

            org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin

            -->