From d346a765e3064a951c5d55119b80b8432a45bcb6 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Wed, 2 Dec 2015 15:51:55 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6062 Updated QueueBrowserSubscription to use a ConcurrentMap to avoid a potential race condition when multiple queue browsers browse multiple queues. --- .../broker/region/QueueBrowserSubscription.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/QueueBrowserSubscription.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/QueueBrowserSubscription.java index 97de9214a6..65f2d7b555 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/QueueBrowserSubscription.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/QueueBrowserSubscription.java @@ -18,9 +18,9 @@ package org.apache.activemq.broker.region; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import javax.jms.JMSException; @@ -42,7 +42,7 @@ public class QueueBrowserSubscription extends QueueSubscription { boolean browseDone; boolean destinationsAdded; - private final Map audit = new HashMap(); + private final ConcurrentMap audit = new ConcurrentHashMap(); private long maxMessages; public QueueBrowserSubscription(Broker broker, SystemUsage usageManager, ConnectionContext context, ConsumerInfo info) throws JMSException { @@ -67,13 +67,7 @@ public class QueueBrowserSubscription extends QueueSubscription { } public boolean isDuplicate(MessageId messageId) { - - if (!audit.containsKey(messageId)) { - audit.put(messageId, Boolean.TRUE); - return false; - } - - return true; + return audit.putIfAbsent(messageId, Boolean.TRUE) != null; } private void checkDone() throws Exception {