From 5356893fac70d9f67a407d836f8cc8260961b792 Mon Sep 17 00:00:00 2001 From: Pascal Schumacher Date: Mon, 10 Feb 2020 20:31:13 +0100 Subject: [PATCH] AMQ-7402: Inconsistent synchronization of getters/setters of some classes Make synchronization consistent or remove it and declare the field volatile. --- .../activemq/broker/region/TopicSubscription.java | 4 ++-- .../region/cursors/AbstractPendingMessageCursor.java | 4 ++-- .../apache/activemq/management/SizeStatisticImpl.java | 10 +++++----- .../activemq/store/kahadb/disk/index/HashIndex.java | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java index 0bf1c4e19e..6f654a4622 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java @@ -504,7 +504,7 @@ public class TopicSubscription extends AbstractSubscription { this.messageEvictionStrategy = messageEvictionStrategy; } - public int getMaxProducersToAudit() { + public synchronized int getMaxProducersToAudit() { return maxProducersToAudit; } @@ -515,7 +515,7 @@ public class TopicSubscription extends AbstractSubscription { } } - public int getMaxAuditDepth() { + public synchronized int getMaxAuditDepth() { return maxAuditDepth; } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java index e0250f28db..bdb1d3e198 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java @@ -260,7 +260,7 @@ public abstract class AbstractPendingMessageCursor implements PendingMessageCurs * @return the maxProducersToAudit */ @Override - public int getMaxProducersToAudit() { + public synchronized int getMaxProducersToAudit() { return maxProducersToAudit; } @@ -279,7 +279,7 @@ public abstract class AbstractPendingMessageCursor implements PendingMessageCurs * @return the maxAuditDepth */ @Override - public int getMaxAuditDepth() { + public synchronized int getMaxAuditDepth() { return maxAuditDepth; } diff --git a/activemq-client/src/main/java/org/apache/activemq/management/SizeStatisticImpl.java b/activemq-client/src/main/java/org/apache/activemq/management/SizeStatisticImpl.java index 9be0d11111..3681083317 100644 --- a/activemq-client/src/main/java/org/apache/activemq/management/SizeStatisticImpl.java +++ b/activemq-client/src/main/java/org/apache/activemq/management/SizeStatisticImpl.java @@ -19,8 +19,8 @@ package org.apache.activemq.management; public class SizeStatisticImpl extends StatisticImpl { private long count; - private long maxSize; - private long minSize; + private volatile long maxSize; + private volatile long minSize; private long totalSize; private SizeStatisticImpl parent; @@ -94,21 +94,21 @@ public class SizeStatisticImpl extends StatisticImpl { /** * @return the maximum size of any step */ - public synchronized void setMaxSize(long size) { + public void setMaxSize(long size) { maxSize = size; } /** * @return the minimum size of any step */ - public synchronized long getMinSize() { + public long getMinSize() { return minSize; } /** * @return the maximum size of any step */ - public synchronized void setMinSize(long size) { + public void setMinSize(long size) { minSize = size; } diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/index/HashIndex.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/index/HashIndex.java index 7a92f05672..df7078eca5 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/index/HashIndex.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/index/HashIndex.java @@ -122,7 +122,7 @@ public class HashIndex implements Index { private Metadata.Marshaller metadataMarshaller = new Metadata.Marshaller(); private HashBin.Marshaller hashBinMarshaller = new HashBin.Marshaller(this); - private Marshaller keyMarshaller; + private volatile Marshaller keyMarshaller; private Marshaller valueMarshaller; @@ -392,7 +392,7 @@ public class HashIndex implements Index { * * @param marshaller */ - public synchronized void setKeyMarshaller(Marshaller marshaller) { + public void setKeyMarshaller(Marshaller marshaller) { this.keyMarshaller = marshaller; }