From e52384b33e720497fd531b70b2cb12382e018139 Mon Sep 17 00:00:00 2001 From: Hamid Mortazavi Date: Mon, 27 Sep 2021 15:18:42 +0100 Subject: [PATCH] Resolve the host only if JMX is enabled --- .../monitor/XMemcachedMbeanServer.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/rubyeye/xmemcached/monitor/XMemcachedMbeanServer.java b/src/main/java/net/rubyeye/xmemcached/monitor/XMemcachedMbeanServer.java index 548f34445..a958a61fe 100644 --- a/src/main/java/net/rubyeye/xmemcached/monitor/XMemcachedMbeanServer.java +++ b/src/main/java/net/rubyeye/xmemcached/monitor/XMemcachedMbeanServer.java @@ -68,21 +68,21 @@ private void initialize() { if (mbserver != null && connectorServer != null && connectorServer.isActive()) { return; } - // 鍒涘缓MBServer - String hostName = null; - try { - InetAddress addr = InetAddress.getLocalHost(); - - hostName = addr.getHostName(); - } catch (IOException e) { - log.error("Get HostName Error", e); - hostName = "localhost"; - } - String host = System.getProperty("hostName", hostName); try { boolean enableJMX = Boolean.parseBoolean(System.getProperty(Constants.XMEMCACHED_JMX_ENABLE, "false")); if (enableJMX) { + // 鍒涘缓MBServer + String hostName = null; + try { + InetAddress addr = InetAddress.getLocalHost(); + + hostName = addr.getHostName(); + } catch (IOException e) { + log.error("Get HostName Error", e); + hostName = "localhost"; + } + String host = System.getProperty("hostName", hostName); mbserver = ManagementFactory.getPlatformMBeanServer(); int port = Integer.parseInt(System.getProperty(Constants.XMEMCACHED_RMI_PORT, "7077")); String rmiName = System.getProperty(Constants.XMEMCACHED_RMI_NAME, "xmemcachedServer");