diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java index 985ebabb1a..618ccb925e 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java @@ -70,6 +70,7 @@ public class ManagementContext implements Service { private int rmiServerPort; private String connectorPath = "/jmxrmi"; private AtomicBoolean started = new AtomicBoolean(false); + private AtomicBoolean connectorStarting = new AtomicBoolean(false); private JMXConnectorServer connectorServer; private ObjectName namingServiceObjectName; private Registry registry; @@ -98,7 +99,12 @@ public class ManagementContext implements Service { JMXConnectorServer server = connectorServer; if (started.get() && server != null) { LOG.debug("Starting JMXConnectorServer..."); - server.start(); + connectorStarting.set(true); + try { + server.start(); + } finally { + connectorStarting.set(false); + } LOG.info("JMX consoles can connect to " + server.getAddress()); } } catch (IOException e) { @@ -129,7 +135,9 @@ public class ManagementContext implements Service { connectorServer = null; if (server != null) { try { - server.stop(); + if (!connectorStarting.get()) { + server.stop(); + } } catch (IOException e) { LOG.warn("Failed to stop jmx connector: " + e.getMessage()); } @@ -217,7 +225,7 @@ public class ManagementContext implements Service { } public boolean isConnectorStarted() { - return connectorServer != null && connectorServer.isActive(); + return connectorStarting.get() || (connectorServer != null && connectorServer.isActive()); } /**