GH-1261: Remove unnecessary volatile modifiers

Resolves https://github.com/spring-projects/spring-amqp/issues/1261

`active` and `running` are only refered to under the lifecycle lock.
Others are set during bean creation.
This commit is contained in:
Gary Russell
2020-10-27 11:25:36 -04:00
parent 0401051bd2
commit 0a0cfe43ee
3 changed files with 19 additions and 18 deletions

View File

@@ -133,6 +133,8 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
private static final boolean MICROMETER_PRESENT = ClassUtils.isPresent(
"io.micrometer.core.instrument.MeterRegistry", AbstractMessageListenerContainer.class.getClassLoader());
private final Object lifecycleMonitor = new Object();
private final ContainerDelegate delegate = this::actualInvokeListener;
protected final Object consumersMonitor = new Object(); //NOSONAR
@@ -183,29 +185,25 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
private int phase = Integer.MAX_VALUE;
private volatile boolean active = false;
private boolean active = false;
private volatile boolean running = false;
private final Object lifecycleMonitor = new Object();
private volatile List<Queue> queues = new CopyOnWriteArrayList<>();
private boolean running = false;
private ErrorHandler errorHandler = new ConditionalRejectingErrorHandler();
private boolean exposeListenerChannel = true;
private volatile MessageListener messageListener;
private MessageListener messageListener;
private volatile AcknowledgeMode acknowledgeMode = AcknowledgeMode.AUTO;
private AcknowledgeMode acknowledgeMode = AcknowledgeMode.AUTO;
private volatile boolean deBatchingEnabled = DEFAULT_DEBATCHING_ENABLED;
private boolean deBatchingEnabled = DEFAULT_DEBATCHING_ENABLED;
private volatile boolean initialized;
private boolean initialized;
private Collection<MessagePostProcessor> afterReceivePostProcessors;
private volatile ApplicationContext applicationContext;
private ApplicationContext applicationContext;
private String listenerId;
@@ -214,17 +212,17 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
@Nullable
private ConsumerTagStrategy consumerTagStrategy;
private volatile boolean exclusive;
private boolean exclusive;
private volatile boolean noLocal;
private boolean noLocal;
private volatile boolean defaultRequeueRejected = true;
private boolean defaultRequeueRejected = true;
private volatile int prefetchCount = DEFAULT_PREFETCH_COUNT;
private int prefetchCount = DEFAULT_PREFETCH_COUNT;
private long idleEventInterval;
private volatile long lastReceive = System.currentTimeMillis();
private long lastReceive = System.currentTimeMillis();
private boolean statefulRetryFatalWithNullMessageId = true;
@@ -250,6 +248,8 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
private JavaLangErrorHandler javaLangErrorHandler = error -> System.exit(EXIT_99);
private volatile List<Queue> queues = new CopyOnWriteArrayList<>();
private volatile boolean lazyLoad;
@Override

View File

@@ -102,6 +102,8 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
private final BlockingQueue<ListenerContainerConsumerFailedEvent> abortEvents = new LinkedBlockingQueue<>();
private final ActiveObjectCounter<BlockingQueueConsumer> cancellationLock = new ActiveObjectCounter<>();
private long startConsumerMinInterval = DEFAULT_START_CONSUMER_MIN_INTERVAL;
private long stopConsumerMinInterval = DEFAULT_STOP_CONSUMER_MIN_INTERVAL;
@@ -118,8 +120,6 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
private Set<BlockingQueueConsumer> consumers;
private final ActiveObjectCounter<BlockingQueueConsumer> cancellationLock = new ActiveObjectCounter<>();
private Integer declarationRetries;
private Long retryDeclarationInterval;

View File

@@ -626,6 +626,7 @@ public class SimpleMessageListenerContainerIntegration2Tests {
this.container = createContainer((m) -> {
throw new Error("testError");
}, false, this.queue.getName());
this.container.setjavaLangErrorHandler(error -> { });
final CountDownLatch latch = new CountDownLatch(1);
this.container.setApplicationEventPublisher(event -> {
if (event instanceof ListenerContainerConsumerFailedEvent) {