Author: markt Date: Tue Nov 27 12:29:36 2012 New Revision: 1414150 URL: http://svn.apache.org/viewvc?rev=1414150&view=rev Log: FRom kkolinko: A ReadWriteLock cannot be used to guard a WeakHashMap. The WeakHashMap may modify itself on get(), as it processes the reference queue of items removed by GC.
Either a plain old lock / synchronization is needed, or some other solution (e.g. org.apache.tomcat.util.collections.ManagedConcurrentWeakHashMap ) Modified: tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java Modified: tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java?rev=1414150&r1=1414149&r2=1414150&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java Tue Nov 27 12:29:36 2012 @@ -18,9 +18,6 @@ package org.apache.tomcat.websocket; import java.util.Map; import java.util.WeakHashMap; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; import javax.websocket.DeploymentException; import javax.websocket.Endpoint; @@ -38,40 +35,24 @@ public class ServerContainerImpl extends // stopped private static Map<ClassLoader, ServerContainerImpl> classLoaderContainerMap = new WeakHashMap<>(); - private static ReadWriteLock classLoaderContainerMapLock = - new ReentrantReadWriteLock(); + private static Object classLoaderContainerMapLock = new Object(); /** - * Intended to be used be implementations of {@link + * Intended to be used by implementations of {@link * javax.websocket.ContainerProvider#getServerContainer()} to obtain the * correct {@link ServerContainer} instance. */ public static ServerContainerImpl getServerContainer() { - // TODO SecurityManager ClassLoader tccl = Thread.currentThread().getContextClassLoader(); ServerContainerImpl result = null; - Lock readlock = classLoaderContainerMapLock.readLock(); - try { - readlock.lock(); + synchronized (classLoaderContainerMapLock) { result = classLoaderContainerMap.get(tccl); - } finally { - readlock.unlock(); - } - - if (result == null) { - Lock writeLock = classLoaderContainerMapLock.writeLock(); - try { - writeLock.lock(); - result = classLoaderContainerMap.get(tccl); - if (result == null) { - result = new ServerContainerImpl(); - classLoaderContainerMap.put(tccl, result); - } - } finally { - writeLock.unlock(); + if (result == null) { + result = new ServerContainerImpl(); + classLoaderContainerMap.put(tccl, result); } } return result; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org