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 c4d49bd1ab..6df48da8a0 100755 --- 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 @@ -1104,8 +1104,15 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index public void doBrowse(List browseList, int max) { final ConnectionContext connectionContext = createConnectionContext(); try { + int maxPageInAttempts = 1; + messagesLock.readLock().lock(); + try { + maxPageInAttempts += (messages.size() / getMaxPageSize()); + } finally { + messagesLock.readLock().unlock(); + } - while (shouldPageInMoreForBrowse(max)) { + while (shouldPageInMoreForBrowse(max) && maxPageInAttempts-- > 0) { pageInMessages(!memoryUsage.isFull(110)); };