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