diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java index f1508f886be..2f0c98cb7e4 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; @@ -2504,26 +2505,26 @@ private QueueMessageReference getMatchingMessage(MessageDispatchNotification mes QueueMessageReference message = null; MessageId messageId = messageDispatchNotification.getMessageId(); - Set set = new LinkedHashSet(); + int size = 0; do { doPageIn(true, false, getMaxPageSize()); pagedInMessagesLock.readLock().lock(); try { - if (!set.addAll(pagedInMessages.values())) { + if (pagedInMessages.size() == size) { // nothing new to check - mem constraint on page in break; - }; + } + size = pagedInMessages.size(); + for (MessageReference ref : pagedInMessages) { + if (ref.getMessageId().equals(messageId)) { + message = (QueueMessageReference) ref; + break; + } + } } finally { pagedInMessagesLock.readLock().unlock(); } - List list = new ArrayList(set); - for (MessageReference ref : list) { - if (ref.getMessageId().equals(messageId)) { - message = (QueueMessageReference) ref; - break; - } - } - } while (set.size() < this.destinationStatistics.getMessages().getCount()); + } while (size < this.destinationStatistics.getMessages().getCount()); if (message == null) { throw new JMSException("Slave broker out of sync with master - Message: "