James Cook wrote:
>
> I just wanted to recap several earlier threads into one. A session bean may
> be used to encapsulate business logic that encompasses several entity beans
> or to wrapper an entity bean. [No, that's not what I want to discuss.] In
> order for the session beans to accomplish this, obviously, they will need a
> reference to the entity beans involved.
>
> Sun's "best practice" documents always show the following steps within a
> business method in the session bean:
>
> public ShoppingCart getShoppingCart() {
> Context initial = new InitialContext();
> Object objref = initial.lookup("java:comp/env/ejb/cart");
> ShoppingCartHome home =
> (ShoppingCartHome)PortableRemoteObject.narrow(objref,
> ShoppingCartHome.class);
> ...
> }
>
> Is this *really* a "best practice" scenario? In my ejb test environment this
> lookup process is averaging 200ms per business method!? This is if all calls
> are executing inprocess. Out of process would certainly be slower. Are they
> showing this for ease of display purposes?
>
There is nothing wrong with a session EJB holding on to its initial JNDI
context and EJB home refs for its lifetime. There is no requirement to
do new home ref lookups within each method. The spec allows doing the
lookup once in setSessionContext. The spec requires that a container
retain home refs across passivation of a session EJB (i.e. EJB
developers do not have to re look them up when activated).
Home refs and EJB refs might go stale over long periods of time.
Typically, a component developer should not worry about compensating for
this case any more than they should worry about compensating for the
server periodically going down.
> Questions
> =========
> 1. For every business method, am I required to initialize a Context object?
>
> 2. For every business method, am I required to lookup my object's home
> interface? There was a thread regarding this a month back, indicating that
> home interfaces could grow stale.
>
> 3. Assuming that a home interface is long-lived (meaning always valid unless
> the server suffers a catastrophic failure), wouldn't it be more appropriate
> to perform the new InitialContext() and the home lookup in the
> setSessionContext() method?
>
> Just trying to clarify the best "best practice".
>
> jim
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".