public EJBHome getHome(String jndiName, Class ejbHome) throws Exception
{
EJBHome home = null;
try
{
home = (EJBHome)homeMap.get(jndiName); //如果map中已存在该EJBHome类型的实例,直接取得
if (home == null)
{ //如果map中不存在该EJBHome类型的实例,产生一个实例,并存储到map里
getInitialContext();
//look up jndi name
Object ref = initContext.lookup(jndiName);
//look up jndi name and cast to Home interface
home = (EJBHome)PortableRemoteObject.narrow(ref, ejbHome);
homeMap.put(jndiName, home);
}
}
catch (NamingException e)
{
//此处不能直接调用Message,容易引起堆栈溢出。
e.printStackTrace();
throw new Exception(e);
}
return home;
}