servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r751811 - /servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AssemblyReferencesListener.java
Date Mon, 09 Mar 2009 19:50:39 GMT
Author: gertv
Date: Mon Mar  9 19:50:38 2009
New Revision: 751811

URL: http://svn.apache.org/viewvc?rev=751811&view=rev
Log:
SMX4NMR-116: Avoid deadlock when shutting down SA

Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AssemblyReferencesListener.java

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AssemblyReferencesListener.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AssemblyReferencesListener.java?rev=751811&r1=751810&r2=751811&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AssemblyReferencesListener.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/AssemblyReferencesListener.java
Mon Mar  9 19:50:38 2009
@@ -40,10 +40,9 @@
 public class AssemblyReferencesListener implements EndpointListener, ExchangeListener {
 
     private final ThreadLocal<ServiceAssembly> assembly = new ThreadLocal<ServiceAssembly>();
-    private final ConcurrentMap<InternalEndpoint, ServiceAssembly> endpoints =
-            new ConcurrentHashMap<InternalEndpoint, ServiceAssembly>();
-    private final ConcurrentMap<ServiceAssembly, AtomicInteger> references =
-            new ConcurrentHashMap<ServiceAssembly, AtomicInteger>();
+    private final ConcurrentMap<InternalEndpoint, ServiceAssembly> endpoints = new
ConcurrentHashMap<InternalEndpoint, ServiceAssembly>();
+    private final ConcurrentMap<ServiceAssembly, AtomicInteger> references = new ConcurrentHashMap<ServiceAssembly,
AtomicInteger>();
+    private final ConcurrentMap<ServiceAssembly, Object> locks = new ConcurrentHashMap<ServiceAssembly,
Object>();
 
     public void setAssembly(ServiceAssembly assembly) {
         this.assembly.set(assembly);
@@ -58,8 +57,9 @@
         AtomicInteger count = references.remove(assembly);
         if (count != null) {
             count.set(0);
-            synchronized (assembly) {
-                assembly.notifyAll();
+            Object lock = locks.remove(assembly);
+            synchronized (lock) {
+                lock.notifyAll();
             }
         }
     }
@@ -71,6 +71,9 @@
             if (references.get(assembly) == null) {
                 references.put(assembly, new AtomicInteger());
             }
+            if (locks.get(assembly) == null) {
+                locks.put(assembly, new Object());
+            }
         }
     }
 
@@ -124,9 +127,10 @@
             AtomicInteger count = references.get(assembly);
             if (count != null) {
                 if (count.get() != 0) {
-                    synchronized (assembly) {
+                    Object lock = locks.get(assembly);
+                    synchronized (lock) {
                         while (count.get() != 0) {
-                            assembly.wait(Long.MAX_VALUE);
+                            lock.wait(Long.MAX_VALUE);
                         }
                     }
                 }
@@ -160,8 +164,9 @@
             AtomicInteger count = references.get(assembly);
             if (count != null) {
                 if (count.decrementAndGet() == 0) {
-                    synchronized (assembly) {
-                        assembly.notifyAll();
+                    Object lock = locks.get(assembly);
+                    synchronized (lock) {
+                        lock.notifyAll();
                     }
                 }
             }



Mime
View raw message