mirror of https://github.com/apache/activemq.git
https://issues.apache.org/activemq/browse/AMQ-2950 - prevent ConcurrentModificationException when removing the connection
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1037675 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fe1bf48a1d
commit
fd4e13634b
|
@ -16,11 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker;
|
package org.apache.activemq.broker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
@ -252,16 +249,26 @@ public class TransactionBroker extends BrokerFilter {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized (xaTransactions) {
|
||||||
|
// first find all txs that belongs to the connection
|
||||||
|
ArrayList<XATransaction> txs = new ArrayList<XATransaction>();
|
||||||
for (XATransaction tx : xaTransactions.values()) {
|
for (XATransaction tx : xaTransactions.values()) {
|
||||||
try {
|
|
||||||
if (tx.getConnectionId().equals(info.getConnectionId()) && !tx.isPrepared()) {
|
if (tx.getConnectionId().equals(info.getConnectionId()) && !tx.isPrepared()) {
|
||||||
tx.rollback();
|
txs.add(tx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// then remove them
|
||||||
|
// two steps needed to avoid ConcurrentModificationException, from removeTransaction()
|
||||||
|
for (XATransaction tx : txs) {
|
||||||
|
try {
|
||||||
|
tx.rollback();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("ERROR Rolling back disconnected client's xa transactions: ", e);
|
LOG.warn("ERROR Rolling back disconnected client's xa transactions: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
next.removeConnection(context, info, error);
|
next.removeConnection(context, info, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue