No, you don't want to do this. EJBs should not contain read/write static
fields, as required by the spec. What you want to do is create a private
field that holds a reference to the home interface of the other bean, and
then initialize that reference in the setEntityContext call. Remember,
setEntityContext is only called once for each instance, but the server can
reuse that instance many times (see the instance lifecycle section of the
spec for entity beans) by pulling it in and out of the pooled state. Also,
you don't have to worry about special handling for passivation - references
to home interfaces are allowed even when the bean is passivated.
Alex Devine
Trilogy Development
office: 512-532-5186 | cell: 512-736-6612 | ICQ: 62256371
|--------+-------------------------------------->
| | Mike Squance |
| | <mike.squance@altus-solution|
| | s.com> |
| | Sent by: |
| | [EMAIL PROTECTED]|
| | eforge.net |
| | |
| | |
| | 06/27/01 07:20 PM |
| | Please respond to jboss-user|
| | |
|--------+-------------------------------------->
>-----------------------------------------------------------------------------------------------------------|
|
|
| To: "JBoss User List (E-mail)" <[EMAIL PROTECTED]>
|
| cc: Mike Squance <[EMAIL PROTECTED]>
|
| Subject: [JBoss-user] Static reference to Home Interface safe?
|
>-----------------------------------------------------------------------------------------------------------|
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
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user