Help! Detect stale ejb homes
Hi Expertises,
Any idea to improve my poor code for detecting stale homes... or no way to detect it? I got exception after i restart/re-deploy ejbs.
I spent big effort on this issue because it gives me significant benefit on performance.
thx
/**
* This is a utility class for obtaining EJB references.
*/
publicfinalclass EJBUtil
{
privatestatic String c_ClusterName =null;
privatestatic String c_ClusterPort =null;
privatestatic Map m_cache =null;
static
{
m_cache =new HashMap();
}
privatestaticsynchronizedvoid setCache(String p_JndiName,
EJBHome p_EjbHome)
{
m_cache.put(p_JndiName, p_EjbHome);
}
privatestaticsynchronizedvoid setCache(String p_JndiName,
DataSource p_DataSource)
{
m_cache.put(p_JndiName, p_DataSource);
}
// ******************* Generic Module ***************
publicstatic EJBHome getEJBHome(String p_JndiName)
{
EJBHome ejbHome = (EJBHome)m_cache.get(p_JndiName);
if (ejbHome ==null){
try
{
Context initial = getInitialContext();
Object objref = initial.lookup(p_JndiName);
ejbHome = (EJBHome)PortableRemoteObject.narrow(objref, EJBHome.class);
setCache(p_JndiName, ejbHome);
return ejbHome;
}
catch (NamingException ne)
{
thrownew GeneralFailureException(ne);
}
}
return ejbHome;
}
publicstatic DataSource getDataSource(String p_JndiName)
{
DataSource dataSource = (DataSource)m_cache.get(p_JndiName);
if (dataSource ==null){
try{
Context initial = getInitialContext();
Object objref = initial.lookup(p_JndiName);
dataSource = (DataSource)PortableRemoteObject.narrow(objref, DataSource.class);
setCache(p_JndiName, dataSource);
return dataSource;
}
catch (NamingException ne)
{
thrownew GeneralFailureException(ne);
}
}
return dataSource;
}
privatestatic Context getInitialContext()throws NamingException
{
try
{
Properties h =new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
if (c_ClusterName==null || c_ClusterPort==null)
{
c_ClusterName = Props.getProperty("CLUSTERNAME");
c_ClusterPort = Props.getProperty("CLUSTERPORT");
ErrorLog.getInstance().clientPrint("Initialize Provider_url - " + c_ClusterName +":" + c_ClusterPort);
}
h.put(Context.PROVIDER_URL,
"t3://" +
c_ClusterName +
":" +
c_ClusterPort);
//For Clustered Environment
//h.put(Context.PROVIDER_URL, "t3://cp2Cluster:7001");
returnnew InitialContext(h);
}
catch (NamingException ne)
{
ErrorLog.getInstance().clientPrint("We were unable to get a connection to the WebLogic server");
ErrorLog.getInstance().clientPrint("Please make sure that the server is running.");
throw ne;
}
}
}

