4 Replies Latest reply on Dec 17, 2009 8:46 AM by jaikiran

    MDB and @Timeout

    fvnkerk

      I am trying to get the @Timeout annotation to work with a MDB implementation.

       

      The MDB extends a super class that has a final method that creates the timer and calls an EJB. The super class also has the annotated timeout method.

       

      To test the implementation I called a method on an EJB that sleeps for 4 seconds. The timeout is set to 2 seconds. The timeout method is not called when it should. The MDB just completes as if no timeout was set. If I run getTimeRemaining on the Timer it returns a negative value.

       

      Am I correct in saying that @Timeout can be used with MDBs, ff so, what am I doing wrong?

       

      A simplified version of the implementation:

       

      public abstract class AbstractMDB{

       

        private ASessionBean sb;

       

        @Resource

        private TimerService ts;

       

        public final onMessage(Message m){

       

          ts.createTimer(2000, null);

          sb.execute(m);

          ts.cancel();

        }

       

        @Timeout

        public void timeout(Timer t){

       

          sb.timeout();

        }

      }

       

      @MessageDriven(...)

      public class ActualMdb extends AbstractMDB{

       

          @Override
          @EJB(mappedName = "...")
          public void setSessionBean(EjbInterface ejb) {

       

              sb = ejb;
          }

      }

        • 1. Re: MDB and @Timeout
          fvnkerk
          Is @Timeout even supported in JBoss 4.2.3.GA?
          • 2. Re: MDB and @Timeout
            jaikiran
            Try this against latest stable JBoss AS-5.1.0.
            • 3. Re: MDB and @Timeout
              fvnkerk

              I tried it on JBoss AS 5.1.0.GA as you suggested but got the same behaviour. The process did however lead me to some other tests to see what could be wrong.

               

              What I found was that if I remove the timer.cancel() call in onMessage(...), the timeout method is called after completion of onMessage(...) and not when the timeout occurs.

               

              So one of the following must be the case:

              1. The timeout method is called on the same instance that created the Timer. I was under the impression that the timeout method can be called on any instance of the Mdb pool.
              2. I only have one MDB instance. Eventhough I set the minimum instances to 5.
              3. The TimerService and @Timeout cannot be used like this.

               

              Not sure which yet.

               

               

               

               


              • 4. Re: MDB and @Timeout
                jaikiran

                TimerService is transaction aware resource. Which means that your calls to createTimer will not be actually complete, unless the transaction completes. In your case, you are calling the cancel even before the transaction (associated with the onMessage) completes. Hence the timer is not being created.