is it safe to store reference?

I'm new to EJB, I've read about dynamic loading in EJB to improve performance. Is it safe to store a reference to object returned by InitialContext, because I assume that InitialContext returns an object representing the "class", not the "instance"?

For example:

publicclass SomeBeanextends ...

/* ... */

private Object objRef;

/* ... */

public SomeDetail getDetail()

{

/* ... */

try{

Context jndiCtx =null;

if (objRef ==null)

{

jndiCtx =new InitialContext();

objRef = jndiCtx.lookup("Detail");

}

Detail = (Detail)

PortableRemoteObject.narrow(objRef, Detail.class);

}catch (Exception NamingException){

NamingException.printStackTrace();

}

/* ... */

}

[1549 byte] By [verdi96] at [2007-9-26 3:29:05]
# 1

No it isn't safe the way you have done it, and the lookup does not return you a "class" object, it returns a stub. You can, however, store references to Objects but these should be executed in the setSessionContext() or setEntityContext() methods - as these are always called before you can call the Remote methods on the bean (ie. when the bean is "resurrected" they will be called again - they will NOT be called every time a Remote method is called).

oxbow_lakes at 2007-6-29 11:53:24 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...