activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1037675 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
Date Mon, 22 Nov 2010 11:34:39 GMT
Author: dejanb
Date: Mon Nov 22 11:34:39 2010
New Revision: 1037675

URL: http://svn.apache.org/viewvc?rev=1037675&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQ-2950 - prevent ConcurrentModificationException
when removing the connection

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java?rev=1037675&r1=1037674&r2=1037675&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransactionBroker.java
Mon Nov 22 11:34:39 2010
@@ -16,11 +16,8 @@
  */
 package org.apache.activemq.broker;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jms.JMSException;
@@ -252,15 +249,25 @@ public class TransactionBroker extends B
             iter.remove();
         }
 
+        synchronized (xaTransactions) {
+            // first find all txs that belongs to the connection
+            ArrayList<XATransaction> txs = new ArrayList<XATransaction>();
+            for (XATransaction tx : xaTransactions.values()) {
+                if (tx.getConnectionId().equals(info.getConnectionId()) && !tx.isPrepared())
{
+                    txs.add(tx);
+                }
+            }
+
+            // then remove them
+            // two steps needed to avoid ConcurrentModificationException, from removeTransaction()
+            for (XATransaction tx : txs) {
+                try {
+                    tx.rollback();
+                } catch (Exception e) {
+                    LOG.warn("ERROR Rolling back disconnected client's xa transactions: ",
e);
+                }
+            }
 
-        for (XATransaction tx : xaTransactions.values()) {
-           try {
-             if (tx.getConnectionId().equals(info.getConnectionId()) && !tx.isPrepared())
{
-                tx.rollback();
-             }
-           } catch (Exception e) {
-               LOG.warn("ERROR Rolling back disconnected client's xa transactions: ", e);
-           }
         }
         next.removeConnection(context, info, error);
     }



Mime
View raw message