5 Replies Latest reply on Apr 17, 2003 3:01 AM by frito

    Is there something like a InitEJB ?

    mafentakis

      Hi guys

      I have an EJB Application that has to do some time consuming initialization before the first usage.

      Is there a possibility to define a InitEJB (like a InitServlet) that will start after deployment of my application ?

      I think that there is not a J2EE standard way to do this and I should use an MBEAN...

      But how can I invoke the MBEAN (that calls my 'init-EJB' ) every time my application is (re)deployed ?

      thank you for feedback of any kind ...

      P.S Please: I m looking for another way than using an init servlet




        • 1. Re: Is there something like a InitEJB ?
          raja05

          You can call a Singleton from your EJB Constructor or setContext. This way, your init is called before EJBs are processed.
          We use this in our MDB code when a set of external properties have to be loaded before the MDBs start picking messages.

          -Raj

          • 2. Re: Is there something like a InitEJB ?
            frito

            AFAIK, you can't predict when the constructor of an EJB is called wheter the context it is running in (e.g. transactional). And again, a singleton is not a singleton in such an environment.
            The proper way to do something like this could be a MBean doing the work and the EJB accessing data from it.

            Greetings,
            Frito

            • 3. Re: Is there something like a InitEJB ?
              raja05

              Hi Frito
              Im not sure what you mean by saying "you cannot predict when constructor is called".
              Doesnt the Constructor get called before its moved to the Pooled state?
              SEction 10.5.1 of EJB Spec requires that a newInstance and setContext be called before moving it from "Does not Exist" state to "Pooled" state/

              Thanks
              Raj

              • 4. Re: Is there something like a InitEJB ?
                mafentakis

                Hi,
                the method setXXSessionContext is called before EJB invokation, but I want to execute a method everytime the ear-application is redeployed ...

                I'm trying the MBEAN way...


                anyway thanks...

                Manolis

                • 5. Re: Is there something like a InitEJB ?
                  frito

                  Hi raja,
                  this is true for entity beans. But what are you going to do, when there is a time consuming job to be done before calling a SLSB? ejbCreate() is not called when create is invoked on the home interface. Instead Class.newInstance(), setSessionContext() and ejbCreate() is called when the first method is called on the remote interface.
                  I think you can configure the jboss pools for your bean, so at least a minimum number of beans is ready and waiting for some action. But this is JBoss configuration done by the deployer.

                  Greetings,

                  Frito