Consistent volatile access to running flag in Lifecycle implementations

Issue: SPR-16596
Issue: SPR-16488

(cherry picked from commit d4a8f76)
This commit is contained in:
Juergen Hoeller
2018-03-15 15:17:55 +01:00
parent 6158634d67
commit b8c92ce931
15 changed files with 76 additions and 109 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -111,10 +111,10 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
private MessageHeaderInitializer headerInitializer;
private final Object lifecycleMonitor = new Object();
private volatile boolean running = false;
private final Object lifecycleMonitor = new Object();
/**
* Create an instance of SimpAnnotationMethodMessageHandler with the given
@@ -298,9 +298,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
@Override
public final boolean isRunning() {
synchronized (this.lifecycleMonitor) {
return this.running;
}
return this.running;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -153,9 +153,7 @@ public abstract class AbstractBrokerMessageHandler
@Override
public void start() {
synchronized (this.lifecycleMonitor) {
if (logger.isInfoEnabled()) {
logger.info("Starting...");
}
logger.info("Starting...");
this.clientInboundChannel.subscribe(this);
this.brokerChannel.subscribe(this);
if (this.clientInboundChannel instanceof InterceptableChannel) {
@@ -173,9 +171,7 @@ public abstract class AbstractBrokerMessageHandler
@Override
public void stop() {
synchronized (this.lifecycleMonitor) {
if (logger.isInfoEnabled()) {
logger.info("Stopping...");
}
logger.info("Stopping...");
stopInternal();
this.clientInboundChannel.unsubscribe(this);
this.brokerChannel.unsubscribe(this);
@@ -206,9 +202,7 @@ public abstract class AbstractBrokerMessageHandler
*/
@Override
public final boolean isRunning() {
synchronized (this.lifecycleMonitor) {
return this.running;
}
return this.running;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,10 +64,10 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
private MessageHeaderInitializer headerInitializer;
private final Object lifecycleMonitor = new Object();
private volatile boolean running = false;
private final Object lifecycleMonitor = new Object();
/**
* Create an instance with the given client and broker channels subscribing
@@ -180,9 +180,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
@Override
public final boolean isRunning() {
synchronized (this.lifecycleMonitor) {
return this.running;
}
return this.running;
}