Hi,
I am wondering if it is safe for an entity bean to maintain a static
reference to the home interface of a second entity bean. This static home
interface would then be accessed within the ejbCreate in order to find an
instance of the second entity bean.
The reason I would like to keep a static reference to the home interface is
for performance reasons. I want to avoid having to do the JNDI lookup to
retrieve the home interface every time the ejbCreate is called. This
ejbCreate will be called very frequently.
The risk that I wonder about is if the ejbCreate is being invoked for more
than one instance at the same time and these multiple instances are
accessing the same home interface reference at the same time.
Is this valid? Is there a better way to accomplish the same thing?
A sample of the code is below.
Thanks for any clarification on this,
Mike.
--
public class MonitoredObjectStatsEEJB
implements EntityBean
{
public EntityTimestamp ejbCreate( ... )
throws CreateException
{
...
MonitoredObjectHome home = findMOHomeInterface();
MonitoredObject mo = home.findByPrimaryKey( entity );
id = mo.getMonitoredObjectId();
...
}
private static MonitoredObjectHome findMOHomeInterface()
{
if ( moHome_ == null )
{
InitialContext jndiContext = new InitialContext( );
Object ref = jndiContext.lookup( "datacache/MonitoredObject" );
moHome_ = (MonitoredObjectHome)
PortableRemoteObject.narrow ( ref, MonitoredObjectHome.class );
}
return moHome_;
}
private static MonitoredObjectHome moHome_ = null;
}
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user