After doing profiling on the system (Weblogic 3.1.X), we decided to use a
caching context to save our home interfaces around.

This method does not make every bean, cache each Home interface around.

============================
public class ServerAccess
{
  private static CacheNamingContext m_context = null;

  static
  {
    try {
    m_context =
     new CacheNamingContext(new InitialContext());
    } catch(NamingException e)
    {
      // do whatever you normally do
    }

  public static Context getInitialContext()
  {
    return m_context;
  }
}

============================
import javax.naming.*;
import java.util.*;

/**
 * A sample service provider that implements a flat namespace in memory.
 */

public class CacheNamingContext implements Context
{
  private Context m_ctx;
  private Hashtable mh_cache = new Hashtable(11);

  public CacheNamingContext(Context ctx)
  {
    m_ctx = ctx;
  }

  public Object lookup(String name) throws NamingException
  {
    if (name.equals(""))
    {
      // Asking to look up this context itself.  Create and return
      // a new instance with its own independent environment.
      return (new CacheNamingContext(m_ctx));
    }
    else if(name.equals("javax.jts.UserTransaction"))
      return m_ctx.lookup(name);

    Object answer = mh_cache.get(name);
    if (answer == null)
    {
      answer = m_ctx.lookup(name);
      mh_cache.put(name, answer);
    }

    return answer;
  }

  public Object lookup(Name name) throws NamingException
  {
    // Flat namespace; no federation; just call string version
    return lookup(name.toString());
  }

  public void bind(String name, Object obj) throws NamingException
  {
    m_ctx.bind(name,obj);
  }

  public void bind(Name name, Object obj) throws NamingException
  {
    m_ctx.bind(name,obj);
  }

  public void rebind(String name, Object obj) throws NamingException
  {
    m_ctx.rebind(name,obj);
  }

  public void rebind(Name name, Object obj) throws NamingException
  {
    m_ctx.rebind(name,obj);
  }

  public void unbind(String name) throws NamingException
  {
    m_ctx.unbind(name);
  }

  public void unbind(Name name) throws NamingException
  {
    m_ctx.unbind(name);
  }

  public void rename(String oldname, String newname)
    throws NamingException
  {
    m_ctx.rename(oldname,newname);
  }

  public void rename(Name oldname, Name newname)
    throws NamingException
  {
    m_ctx.rename(oldname,newname);
  }

  public NamingEnumeration list(String name)
    throws NamingException
  {
    return m_ctx.list(name);
  }

  public NamingEnumeration list(Name name)
    throws NamingException
  {
    return m_ctx.list(name);
  }

  public NamingEnumeration listBindings(String name)
    throws NamingException
  {
    return m_ctx.listBindings(name);
  }

  public NamingEnumeration listBindings(Name name)
    throws NamingException
  {
    return m_ctx.listBindings(name);
  }

  public void destroySubcontext(String name) throws NamingException
  {
    m_ctx.destroySubcontext(name);
  }

  public void destroySubcontext(Name name) throws NamingException
  {
    m_ctx.destroySubcontext(name);
  }

  public Context createSubcontext(String name)
    throws NamingException
  {
    return m_ctx.createSubcontext(name);
  }

  public Context createSubcontext(Name name) throws NamingException
  {
    return m_ctx.createSubcontext(name);
  }

  public Object lookupLink(String name) throws NamingException
  {
    return lookup(name);
  }

  public Object lookupLink(Name name) throws NamingException
  {
    // Flat namespace; no federation; just call string version
    return lookupLink(name.toString());
  }

  public NameParser getNameParser(String name)
    throws NamingException
  {
    return m_ctx.getNameParser(name);
  }

  public NameParser getNameParser(Name name) throws NamingException
  {
    return m_ctx.getNameParser(name);
  }

  public String composeName(String name, String prefix)
    throws NamingException
  {
    Name result = composeName(new CompositeName(name),
                              new CompositeName(prefix));
    return result.toString();
  }

  public Name composeName(Name name, Name prefix)
    throws NamingException
  {
    Name result = (Name)(prefix.clone());
    result.addAll(name);
    return result;
  }

  public Object addToEnvironment(String propName, Object propVal)
    throws NamingException
  {
    return null;
  }

  public Object removeFromEnvironment(String propName)
    throws NamingException
  {
    return null;
  }

  public Hashtable getEnvironment() throws NamingException
  {
    return null;
  }

  public void close() throws NamingException
  {
  }
}
=============

> -----Original Message-----
> From: George Richards [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 31, 1999 2:45 PM
> To: [EMAIL PROTECTED]
> Subject: Caching home interfaces
>
>
> I'm creating a JSP -> EJB application. I considering using a session
> scope bean at the JSP level to cache the home interfaces my JSP pages
> will use. The cache will be lazily filled, the interface will only be
> looked up once the first request for it is made.
>
> Does this seem like a good idea?
>
> Any comments on caching home interfaces?
>
> Is there a problem with multiple pages sharing the same home
> interface?
>
> What is the cost of the JNDI lookup that returns the home interface?
>
> Thank a lot,
> George
>
>
> __________________________________________________
> Do You Yahoo!?
> Bid and sell for free at http://auctions.yahoo.com
>
> ==============================================================
> =============
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff EJB-INTEREST".  For general help,
> send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to