5 Replies Latest reply on Apr 26, 2002 4:11 PM by Guy Rouillier

    Client pooling of EJB references

    Guy Rouillier Newbie

      I'm experimenting with a particular EJB. The methods are lightweight, with the result being that call setup (lookup of home, create of remote) is taking longer than the methods themselves. I'm wondering if I could address this by keeping a pool of open EJB references on the client. The client is a bunch of JSP pages under Tomcat in a separate JVM on a different host. I'm pretty familiar with pools in general and with the JBoss pool in particular. But (1) will a pool of open EJB references work and not cause resource issues, and (2) where in the Tomcat JSP environment would I keep such a pool so that it can be accessed by all pages? Are there better alternatives?

        • 1. Re: Client pooling of EJB references
          J. Wolfgang Kaltz Novice

          We have a similar situation; I clocked the lookup of home to take quite long, so we are "pooling" the home interfaces (I'm just putting them in a Hashtable); you can definitely do this without risk and that already saves a lot of time.

          I'm using the ServiceLocator pattern, so a singleton (static) instance of this java class with a Hashtable of home interfaces which have already been looked up (plus any other resources you need to look up). This ServiceLocator lives in your client (in your case, Tomcat). All you need to do is find a reasonable place to initialize it since it needs initialization parameters (such as EJB naming host name & port) - I'm doing that when the first user logs in.

          • 2. Re: Client pooling of EJB references
            Guy Rouillier Newbie

            Thanks for the ideas. Let's say I want to store the home object somewhere. Where should I put it - into a session variable? That would limit it to this one session. I'd like to be able to share the home objects across multiple sessions/users. I can't figure out where I would put this pool so that multiple users can get to it.

            • 3. Re: Client pooling of EJB references
              David Jencks Master

              You could always run tomcat by itself in jbossmx... and use an mbean;-) I haven't tried it, but could you bind them in tomcat's jndi?

              • 4. Re: Client pooling of EJB references
                Johan Isacsson Newbie

                I have noticed that if you have a cached home object and try to use it after jboss has been restarted it will not work very well. If i remember it right it would give you strange errors such as "No such entity" or similar.
                I guess that this problem never occuer if you have jboss and tomcat running in the same VM but you should test it if you have them separated.

                I used a singelton to store my pool of home objects and read the "init params" from tomcat's jndi context.

                • 5. Re: Client pooling of EJB references
                  Guy Rouillier Newbie

                  I've noticed everyone on this discussion mentions caching the home interface. Why that instead of the remote one? I've seen no problems with several different clients keeping a remote object open against the same EJB. Does the lookup of the home take the majority of the setup time compared to creating the remote object?