diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java index 25c657e245..1f2be699ec 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java @@ -344,10 +344,10 @@ public class ServerConsumerImpl implements ServerConsumer, ReadyListener { ref.getQueue().acknowledge(ref); } - } + if (message.isLargeMessage() && this.supportLargeMessage) { + largeMessageDeliverer = new LargeMessageDeliverer((LargeServerMessage) message, ref); + } - if (message.isLargeMessage() && this.supportLargeMessage) { - largeMessageDeliverer = new LargeMessageDeliverer((LargeServerMessage) message, ref); } lockDelivery.readLock().lock(); @@ -559,7 +559,13 @@ public class ServerConsumerImpl implements ServerConsumer, ReadyListener { @Override public void setStarted(final boolean started) { synchronized (lock) { - this.started = browseOnly || started; + lockDelivery.writeLock().lock(); + try { + this.started = browseOnly || started; + } + finally { + lockDelivery.writeLock().unlock(); + } } // Outside the lock @@ -966,6 +972,10 @@ public class ServerConsumerImpl implements ServerConsumer, ReadyListener { public boolean deliver() throws Exception { lockDelivery.readLock().lock(); try { + if (!started) { + return false; + } + LargeServerMessage currentLargeMessage = largeMessage; if (currentLargeMessage == null) { return true;