https://issues.apache.org/jira/browse/AMQ-4930  - limit browse page in 
iterations in case cursor and store are out of sync - avoid a spin when store 
does not return messages


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/8216e7f4
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/8216e7f4
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/8216e7f4

Branch: refs/heads/trunk
Commit: 8216e7f4d5e275cc41a3d21dea8d7ffaa430719e
Parents: 41ca0d9
Author: gtully <[email protected]>
Authored: Thu Oct 9 23:05:09 2014 +0100
Committer: gtully <[email protected]>
Committed: Thu Oct 16 23:35:17 2014 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/activemq/broker/region/Queue.java  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/8216e7f4/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java
----------------------------------------------------------------------
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 c4d49bd..6df48da 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<Message> 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));
             };
 

Reply via email to