5 Replies Latest reply on Feb 20, 2002 12:00 AM by hchirino

    How to wait in a MDB ?

    lbroudoux

      Hello,

      I need to implement a MessageDriven Bean that wait a moment in its execution until the end of another process.
      The other process end notification is quite basic : it produces a file and my MDB only has to check its existence.

      I have tried to do it this way : calling the wait() method in my MDB (inherited from Object).
      But I always have the following runtime exception :

      [VersionTargetChecker] TRANSACTION ROLLBACK EXCEPTION:null
      Embedded Exception
      current thread not owner; nested exception is:
      javax.ejb.EJBException: null
      Embedded Exception
      current thread not owner
      [VersionTargetChecker] java.lang.IllegalMonitorStateException: current thread not owner
      [VersionTargetChecker] at java.lang.Object.wait(Native Method)
      [VersionTargetChecker] at mma.it.service.mdb.VersionTargetChecker.onMessage(VersionTargetChecker.java:142)
      [VersionTargetChecker] at java.lang.reflect.Method.invoke(Native Method)
      [VersionTargetChecker] at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.java:400)
      [VersionTargetChecker] at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:58)
      [VersionTargetChecker] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
      ...


      Could someone explain me, please, what java.lang.IllegalMonitorStateException is ?
      This is certainly due to a design problem ... Has anyone a better idea (or ever solve this kind of problem) ?
      (with a dedicated object, extended from Thread, started by my MDB ?)

      Thanks a lot for your help,

      Laurent

        • 1. Re: How to wait in a MDB ?
          ppetit

          I think you cannot use thread management like wait()within an EJB.
          FYI:
          wait(long timeout, int nanos)
          Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

          Perhaps, if your EJBs involved in your process are in the same JVM, the process writing the file could notify the MDB through a listener after completion (Observable Pattern is a good candidate for this).
          It's just an idea.
          Philippe

          • 2. Re: How to wait in a MDB ?
            lbroudoux

            Thanks Philippe for your reply ...
            And sorry for the 2 posts (a mistake on Edit/Preview screens !)

            I have finally succeed in making my MDB wait until the end of the other process. I've done this by making
            current thread retrieving my MDB's monitor with synchronized call (on "this") before wait().
            (The other process is not a Java process ...)

            I have now some other problems : transaction timeout while MDB is waiting (and the trans-attribute
            NotSupported doesn't seems to be effective), confusion between topics
            (MDBs received messages from topic they aren't listening to ...).
            I'm trying to make a SB on JBoss on a first machine, publishing messages on topics on a second machine (using
            the JMS ressource adaptor).

            Hum ... it's time to dive back into this problems !

            Regards,

            Laurent

            • 3. Re: How to wait in a MDB ?

              This has been discusses (and solved before - Hiram do you remember this?). Search on the dev list.

              //Peter

              • 4. Re: How to wait in a MDB ?
                nikolaj

                Hi Peter,
                Stupid question here... where is the "dev" list. Thanks.

                • 5. Re: How to wait in a MDB ?
                  hchirino

                  The fix is use a CMT with NotSupported or use a BMT.
                  In either case the Transaction Manager is not used since a 2 phase commit will not be required.

                  I'm not sure if this has been back ported to 2.4.4, but I know it is in 3.0.

                  Regards,
                  Hiram