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;

}

}

}

[6208 byte] By [kl96aj] at [2007-9-26 12:26:27]
# 1
Is it really not a such solution :(
kl96aj at 2007-7-2 3:08:02 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
You got several replies in the EJB forum (now you see a pitfall of cross-posting). I'm not sure we understood exactly what you were trying to do but anyway why not continue this in the EJB forum so we all know where we are?
gseel at 2007-7-2 3:08:02 > top of Java-index,Other Topics,Patterns & OO Design...