You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/05/15 15:01:32 UTC

tomee git commit: TOMEE-1585 liveHandleRegistry was not thread safe

Repository: tomee
Updated Branches:
  refs/heads/master ff024a2cc -> 7ddafafc5


TOMEE-1585 liveHandleRegistry was not thread safe


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/7ddafafc
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/7ddafafc
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/7ddafafc

Branch: refs/heads/master
Commit: 7ddafafc58708d9cb1356c646a922b76c477452e
Parents: ff024a2
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Fri May 15 15:01:21 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Fri May 15 15:01:21 2015 +0200

----------------------------------------------------------------------
 .../openejb/core/ivm/BaseEjbProxyHandler.java   | 51 ++++++++++----------
 1 file changed, 26 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/7ddafafc/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
index e632778..ac0e1dd 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
@@ -29,16 +29,6 @@ import org.apache.openejb.spi.ContainerSystem;
 import org.apache.openejb.spi.SecurityService;
 import org.apache.openejb.util.proxy.LocalBeanProxyFactory;
 
-import javax.ejb.AccessLocalException;
-import javax.ejb.EJBException;
-import javax.ejb.EJBTransactionRequiredException;
-import javax.ejb.EJBTransactionRolledbackException;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.TransactionRequiredLocalException;
-import javax.ejb.TransactionRolledbackLocalException;
-import javax.transaction.TransactionRequiredException;
-import javax.transaction.TransactionRolledbackException;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -57,12 +47,23 @@ import java.rmi.NoSuchObjectException;
 import java.rmi.Remote;
 import java.rmi.RemoteException;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.locks.ReentrantLock;
+import javax.ejb.AccessLocalException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBTransactionRequiredException;
+import javax.ejb.EJBTransactionRolledbackException;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.TransactionRequiredLocalException;
+import javax.ejb.TransactionRolledbackLocalException;
+import javax.transaction.TransactionRequiredException;
+import javax.transaction.TransactionRolledbackException;
 
 import static org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.CLASSLOADER_COPY;
 import static org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.COPY;
@@ -605,20 +606,20 @@ public abstract class BaseEjbProxyHandler implements InvocationHandler, Serializ
     protected abstract Object _writeReplace(Object proxy) throws ObjectStreamException;
 
     protected void registerHandler(final Object key, final BaseEjbProxyHandler handler) {
-        HashSet set = (HashSet) getLiveHandleRegistry().get(key);
-        if (set != null) {
-            final ReentrantLock l = lock;
-            l.lock();
-
-            try {
-                set.add(handler);
-            } finally {
-                l.unlock();
-            }
-        } else {
+        Set set = (Set) getLiveHandleRegistry().get(key);
+        if (set == null) {
             set = new HashSet();
+            final Object existing = getLiveHandleRegistry().putIfAbsent(key, set);
+            if (existing != null) {
+                set = Set.class.cast(existing);
+            }
+        }
+        final ReentrantLock l = lock;
+        l.lock();
+        try {
             set.add(handler);
-            getLiveHandleRegistry().put(key, set);
+        } finally {
+            l.unlock();
         }
     }
 
@@ -637,7 +638,7 @@ public abstract class BaseEjbProxyHandler implements InvocationHandler, Serializ
         this.beanContextRef = new WeakReference<BeanContext>(beanContext);
     }
 
-    public HashMap getLiveHandleRegistry() {
+    public ConcurrentMap getLiveHandleRegistry() {
         final BeanContext beanContext = getBeanContext();
         ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
         if (proxyRegistry == null) {
@@ -672,7 +673,7 @@ public abstract class BaseEjbProxyHandler implements InvocationHandler, Serializ
 
     private static class ProxyRegistry {
 
-        protected final HashMap liveHandleRegistry = new HashMap();
+        protected final ConcurrentMap liveHandleRegistry = new ConcurrentHashMap();
     }
 
 }