resolve concurrent modification

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@634487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-03-07 00:57:55 +00:00
parent f4ca650108
commit cf55702288
1 changed files with 19 additions and 7 deletions

View File

@ -17,6 +17,7 @@
package org.apache.activemq.broker.region;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -110,12 +111,19 @@ public class TopicSubscription extends AbstractSubscription {
// only page in a 1000 at a time - else we could
// blow da memory
pageInSize = Math.max(1000, pageInSize);
LinkedList list = matched.pageInList(pageInSize);
MessageReference[] oldMessages = messageEvictionStrategy.evictMessages(list);
int messagesToEvict = oldMessages.length;
for (int i = 0; i < messagesToEvict; i++) {
MessageReference oldMessage = oldMessages[i];
discard(oldMessage);
LinkedList list = null;
MessageReference[] oldMessages=null;
synchronized(matched){
list = matched.pageInList(pageInSize);
oldMessages = messageEvictionStrategy.evictMessages(list);
}
int messagesToEvict = 0;
if (oldMessages != null){
messagesToEvict = oldMessages.length;
for (int i = 0; i < messagesToEvict; i++) {
MessageReference oldMessage = oldMessages[i];
discard(oldMessage);
}
}
// lets avoid an infinite loop if we are given a bad
// eviction strategy
@ -454,7 +462,11 @@ public class TopicSubscription extends AbstractSubscription {
* @return the list
*/
public synchronized List<MessageReference> getInFlightMessages(){
return matched.pageInList(1000);
List<MessageReference> result = new ArrayList<MessageReference>();
synchronized(matched) {
result.addAll(matched.pageInList(1000));
}
return result;
}
}