3 Replies Latest reply on Apr 5, 2005 9:44 PM by mooktarus

    How do I start session beans at deployment time?


      I'm working on a stateless session bean, call it ExampleBean, and I want to start up instances of it before it's used, i.e. start the app with one or more instances in the pool. The reason I want this is because the startup time is rather lengthy, and I want this startup time out of the way before the users need it.

      It occurs to me that what I really want is to create one or more instances of ExampleBean just after the EAR is deployed (call it ExampleEJB.ear). Would I create an MBean to do this, or is there some config file or deployment descriptor I need to look at?


        • 1. Re: How do I start session beans at deployment time?

          Update: I tried to do this by extending the Standard Stateless SessionBean container-configuration, and setting the MinimumSize attribute to 1 (in jboss.xml). When I RTFM'd, I found the following disclaimer:

          MinimumSize: The MinimumSize element gives the minimum number of instances to keep in the pool, although JBoss does not currently seed an InstancePool to the MinimumSize value.

          Would the best way to do this be to create my own InstancePool implementation that does actually seed the pool? Or am I missing something?

          • 2. Re: How do I start session beans at deployment time?
            Dimitris Andreadis Master

            What is that your session bean is doing that takes up so much time?

            It seems to me you need more like an adapter to some external resource or something. If you want to have full control over the lifecycle of this "external" thing, you'll have to write a JCA adapter (which is quite difficult) or create an MBean service that manages a pool of whatever you want to manage, then the SLSB accesses the MBean (a lot easier but not so portable).

            A third solution (a hack really) is to write an MBean that is deployed after the SLSB and spawns a number of concurrent threads calling the SLSB just to cause the bean pool to be populated. (I didn't say this).

            A fourth solutions is to write your own pool implementation.

            It is usually assumed that SLSB creation time is small, so that the server has the freedom to alter the pool size (enlarge/shrink) to match the client load...

            • 3. Re: How do I start session beans at deployment time?

              To make a long story short, this external thing is a perl app that takes a while to initialize, then "listens" for requests. The MBean service idea sounds most promising, I'll give that a try.