fixed a potential hole around lock usage

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@961272 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2010-07-07 07:35:31 +00:00
parent 28180b35bd
commit 720ff40ac0
1 changed files with 3 additions and 7 deletions

View File

@ -1677,23 +1677,19 @@ public class Queue extends BaseDestination implements Task, UsageListener {
}
// Only add new messages, not already pagedIn to avoid multiple
// dispatch attempts
pagedInMessagesLock.readLock().lock();
pagedInMessagesLock.writeLock().lock();
try {
resultList = new ArrayList<QueueMessageReference>(result.size());
for (QueueMessageReference ref : result) {
if (!pagedInMessages.containsKey(ref.getMessageId())) {
pagedInMessagesLock.readLock().unlock();
pagedInMessagesLock.writeLock().lock();
pagedInMessages.put(ref.getMessageId(), ref);
pagedInMessagesLock.readLock().lock();
pagedInMessagesLock.writeLock().unlock();
resultList.add(ref);
} else {
ref.decrementReferenceCount();
}
}
} finally {
pagedInMessagesLock.readLock().unlock();
pagedInMessagesLock.writeLock().unlock();
}
} else {
// Avoid return null list, if condition is not validated