[jboss-cvs] JBossAS SVN: r107606 - in projects/naming/branches/Branch_5_0/jnpserver: src/main/java/org/jboss/naming and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Aug 14 00:47:21 EDT 2010
Author: jason.greene at jboss.com
Date: 2010-08-14 00:47:21 -0400 (Sat, 14 Aug 2010)
New Revision: 107606
Modified:
projects/naming/branches/Branch_5_0/jnpserver/pom.xml
projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java
Log:
Move to a non-blocking thread association mechanism (Fixes JBPAPP-4787)
Modified: projects/naming/branches/Branch_5_0/jnpserver/pom.xml
===================================================================
--- projects/naming/branches/Branch_5_0/jnpserver/pom.xml 2010-08-14 00:54:23 UTC (rev 107605)
+++ projects/naming/branches/Branch_5_0/jnpserver/pom.xml 2010-08-14 04:47:21 UTC (rev 107606)
@@ -21,7 +21,7 @@
<properties>
<!-- compile dependencies -->
<version.org.jboss.logging.spi>2.0.5.GA</version.org.jboss.logging.spi>
- <version.org.jboss.common.core>2.2.10.GA</version.org.jboss.common.core>
+ <version.org.jboss.common.core>2.2.16.GA</version.org.jboss.common.core>
<!-- testing dependencies -->
<version.org.jboss.microcontainer>2.0.0.CR5</version.org.jboss.microcontainer>
<version.org.jboss.test>1.1.1.GA</version.org.jboss.test>
Modified: projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java
===================================================================
--- projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java 2010-08-14 00:54:23 UTC (rev 107605)
+++ projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java 2010-08-14 04:47:21 UTC (rev 107606)
@@ -23,6 +23,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.EnumSet;
import java.util.Hashtable;
import java.util.List;
import java.util.WeakHashMap;
@@ -32,13 +33,16 @@
import javax.naming.NamingException;
import javax.naming.spi.ObjectFactory;
+import org.jboss.util.collection.ConcurrentReferenceHashMap;
+import org.jboss.util.collection.ConcurrentReferenceHashMap.Option;
+import org.jboss.util.collection.ConcurrentReferenceHashMap.ReferenceType;
import org.jnp.interfaces.NamingContext;
import org.jnp.server.NamingServer;
/**
* Implementation of "java:comp" namespace factory. The context is associated
* with the thread class loader.
- *
+ *
* @author <a href="mailto:rickard.oberg at telkel.com">Rickard Oberg</a>
* @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
@@ -48,9 +52,12 @@
implements ObjectFactory
{
// Constants -----------------------------------------------------
-
+
// Attributes ----------------------------------------------------
- private static WeakHashMap classloaderKeyedEncs = new WeakHashMap();
+
+ private static ConcurrentReferenceHashMap<ClassLoader, Context> classloaderKeyedEncs =
+ new ConcurrentReferenceHashMap<ClassLoader, Context>
+ (16, .75f, 4, ReferenceType.WEAK, ReferenceType.STRONG, EnumSet.of(Option.IDENTITY_COMPARISONS));
private static ClassLoader topLoader;
private static ThreadLocalStack<Object> encIdStack = new ThreadLocalStack<Object>();
private static ConcurrentHashMap<Object, Context> encById = new ConcurrentHashMap<Object, Context>();
@@ -81,7 +88,7 @@
}
// Static --------------------------------------------------------
-
+
public static void setTopClassLoader(ClassLoader topLoader)
{
ENCFactory.topLoader = topLoader;
@@ -111,31 +118,30 @@
}
// Get naming for this component
ClassLoader ctxClassLoader = GetTCLAction.getContextClassLoader();
- synchronized (classloaderKeyedEncs)
+ Context compCtx = (Context) classloaderKeyedEncs.get(ctxClassLoader);
+
+ // If this is the first time we see ctxClassLoader first check to see
+ // if a parent ClassLoader has created an ENC namespace.
+ if (compCtx == null)
{
- Context compCtx = (Context) classloaderKeyedEncs.get(ctxClassLoader);
-
- /* If this is the first time we see ctxClassLoader first check to see
- if a parent ClassLoader has created an ENC namespace.
- */
+ ClassLoader loader = ctxClassLoader;
+ GetParentAction action = new GetParentAction(ctxClassLoader);
+ while( loader != null && loader != topLoader && compCtx == null )
+ {
+ compCtx = (Context) classloaderKeyedEncs.get(loader);
+ loader = action.getParent();
+ }
+ // If we did not find an ENC create it
if (compCtx == null)
{
- ClassLoader loader = ctxClassLoader;
- GetParentAction action = new GetParentAction(ctxClassLoader);
- while( loader != null && loader != topLoader && compCtx == null )
- {
- compCtx = (Context) classloaderKeyedEncs.get(loader);
- loader = action.getParent();
- }
- // If we did not find an ENC create it
- if( compCtx == null )
- {
- compCtx = createContext(environment);
- classloaderKeyedEncs.put(ctxClassLoader, compCtx);
- }
+ compCtx = createContext(environment);
+ Context old = classloaderKeyedEncs.putIfAbsent(ctxClassLoader, compCtx);
+ if (old != null)
+ compCtx = old;
}
- return compCtx;
}
+
+ return compCtx;
}
/**
More information about the jboss-cvs-commits
mailing list