Typical EJB applications make use of a client layer that invokes one or many EJBs several times. This is true for many web applications as well. When q client layer must use a particular bean multiple times, you'll want to make an effort to improve the performance of the JNDI call that looks up the bean. In addition, it would be nice to reduce duplicated code. To improve client performance, create a utility object that encapsulates the JNDI lookup of EJB home object reference. In addition to performing home lookups, the utility object can cache the home reference for reuse.

This tip contains an example - a utility object that looks up the home object for an EJB:

public class SomeBeanHomeCache {
    private static SomeBeanHome _home = null;
    public static EquityHome getHome() throws NamingException {
        if (_home == null) {
            try {
                InitialContext context = new InitialContext();
                _home = (SomeBeanHomePortableRemoteObject.narrow(
            catch (Exception e) {
                // handle error
        return _home;