From 720ff40ac026c4700e3c2306e537d9c497206f4b Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Wed, 7 Jul 2010 07:35:31 +0000 Subject: [PATCH] fixed a potential hole around lock usage git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@961272 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/activemq/broker/region/Queue.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java index 97e6f3b143..4059289b92 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -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(result.size()); for (QueueMessageReference ref : result) { - if (!pagedInMessages.containsKey(ref.getMessageId())) { - pagedInMessagesLock.readLock().unlock(); - pagedInMessagesLock.writeLock().lock(); + if (!pagedInMessages.containsKey(ref.getMessageId())) { 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