dev@glassfish.java.net

Proposed Commit for 9810

From: Mahesh Kannan <Mahesh.Kannan_at_Sun.COM>
Date: Wed, 18 Nov 2009 09:40:31 -0800

Jerome,
  Need your approval to checkin the fix for 9810.

Scott verified the patch and he confirmed that this fix removes the 2x
perf regression.

ejb devtests and QLs passed.

Here are the diffs:

Index:
common/container-common/src/main/java/com/sun/enterprise/container/common/impl/ComponentEnvManagerImpl.java
===================================================================
---
common/container-common/src/main/java/com/sun/enterprise/container/common/impl/ComponentEnvManagerImpl.java
(revision 34328)
+++
common/container-common/src/main/java/com/sun/enterprise/container/common/impl/ComponentEnvManagerImpl.java
(working copy)
@@ -1000,6 +1000,12 @@
 
         private EjbReferenceDescriptor ejbRef;
 
+ private volatile EjbNamingReferenceManager ejbRefMgr;
+
+ private volatile Object cachedResult = null;
+
+ private Boolean cacheable;
+
         // Note : V2 had a limited form of ejb-ref caching. It only
applied
         // to EJB 2.x Home references where the target lived in the
same application
         // as the client. It's not clear how useful that even is and
it's of limited
@@ -1014,12 +1020,25 @@
                 throws NamingException {
 
             Object result = null;
- EjbNamingReferenceManager ejbRefMgr =
habitat.getByContract(EjbNamingReferenceManager.class);
+ if (ejbRefMgr == null) {
+ synchronized (this) {
+ if (ejbRefMgr == null) {
+ ejbRefMgr =
habitat.getByContract(EjbNamingReferenceManager.class);
+ cacheable = new
Boolean(ejbRefMgr.isEjbReferenceCacheable(ejbRef));
+ }
+ }
+ }
 
             if (ejbRefMgr != null) {
-
- result = ejbRefMgr.resolveEjbReference(ejbRef, ctx);
-
+ if ((cacheable != null) && (cacheable.booleanValue() ==
true)) {
+ if (cachedResult != null) {
+ result = cachedResult;
+ } else {
+ result = cachedResult =
ejbRefMgr.resolveEjbReference(ejbRef, ctx);
+ }
+ } else {
+ result = ejbRefMgr.resolveEjbReference(ejbRef, ctx);
+ }
             }
 
             if( result == null ) {
Index:
ejb/ejb-container/src/main/java/com/sun/ejb/EjbNamingReferenceManagerImpl.java
===================================================================
---
ejb/ejb-container/src/main/java/com/sun/ejb/EjbNamingReferenceManagerImpl.java
(revision 34328)
+++
ejb/ejb-container/src/main/java/com/sun/ejb/EjbNamingReferenceManagerImpl.java
(working copy)
@@ -187,8 +187,13 @@
     }
 
     public boolean isEjbReferenceCacheable(EjbReferenceDescriptor
ejbRefDesc) {
+ // Ejb-ref is only eligible for caching if it refers to the legacy
+ // Home view and it is resolved to an ejb within the same
application.
+ return ( (!ejbRefDesc.isEJB30ClientView()) &&
+ (ejbRefDesc.getEjbDescriptor() != null) );
+
         // caching not enabled.
- return false;
     }