Updated QueueBrowserSubscription to use a ConcurrentMap to avoid a
potential race condition when multiple queue browsers browse
multiple queues.
This commit is contained in:
Christopher L. Shannon (cshannon) 2015-12-02 15:51:55 +00:00
parent 8363c99b51
commit d346a765e3
1 changed files with 4 additions and 10 deletions

View File

@ -18,9 +18,9 @@ package org.apache.activemq.broker.region;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -42,7 +42,7 @@ public class QueueBrowserSubscription extends QueueSubscription {
boolean browseDone; boolean browseDone;
boolean destinationsAdded; boolean destinationsAdded;
private final Map<MessageId, Object> audit = new HashMap<MessageId, Object>(); private final ConcurrentMap<MessageId, Object> audit = new ConcurrentHashMap<MessageId, Object>();
private long maxMessages; private long maxMessages;
public QueueBrowserSubscription(Broker broker, SystemUsage usageManager, ConnectionContext context, ConsumerInfo info) throws JMSException { 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) { public boolean isDuplicate(MessageId messageId) {
return audit.putIfAbsent(messageId, Boolean.TRUE) != null;
if (!audit.containsKey(messageId)) {
audit.put(messageId, Boolean.TRUE);
return false;
}
return true;
} }
private void checkDone() throws Exception { private void checkDone() throws Exception {