How to improve client-side EJB lookup




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 a client layer must use a
particular bean multiple times, there needs to be an effort made to improve the
performance of the JNDI call that looks up the bean. In addition, it would be
nice to reduce duplicated code.


Tip :

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 {


static SomeBeanHome _home = null;


static EquityHome getHome() throws NamingException {


(_home == null) {




context = new InitialContext();

_home = (SomeBeanHome) PortableRemoteObject.narrow(




catch (Exception e) {


// handle error







Give some Likes to Authors


Support, help community and write on social network.