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,15 +249,25 @@ 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()) {
|
||||||
|
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);
|
next.removeConnection(context, info, error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue