Author: degenaro Date: Fri Feb 1 15:39:08 2019 New Revision: 1852757 URL: http://svn.apache.org/viewvc?rev=1852757&view=rev Log: UIMA-5977 DUCC Web Server (WS) JMX thread leak
Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/BrokerHelper.java uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/DatabaseHelper.java uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/JmxHelper.java Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/BrokerHelper.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/BrokerHelper.java?rev=1852757&r1=1852756&r2=1852757&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/BrokerHelper.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/BrokerHelper.java Fri Feb 1 15:39:08 2019 @@ -32,13 +32,9 @@ import java.util.TreeSet; import javax.management.Attribute; import javax.management.AttributeList; import javax.management.InstanceNotFoundException; -import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.ReflectionException; import javax.management.openmbean.CompositeData; -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; import org.apache.uima.ducc.common.utils.DuccLogger; import org.apache.uima.ducc.common.utils.DuccPropertiesResolver; @@ -55,10 +51,6 @@ public class BrokerHelper extends JmxHel return new BrokerHelper(); } - private JMXServiceURL jmxServiceUrl = null;; - private JMXConnector jmxc; - private MBeanServerConnection mbsc; - private OperatingSystemMXBean remoteOperatingSystem; private ThreadMXBean remoteThread; @@ -133,7 +125,7 @@ public class BrokerHelper extends JmxHel String location = "populateRemoteOperatingSystem"; try { remoteOperatingSystem = ManagementFactory.newPlatformMXBeanProxy( - mbsc, + getMBSC(), ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class); } @@ -146,7 +138,7 @@ public class BrokerHelper extends JmxHel String location = "populateRemoteThread"; try { remoteThread = ManagementFactory.newPlatformMXBeanProxy( - mbsc, + getMBSC(), ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class); } @@ -179,7 +171,7 @@ public class BrokerHelper extends JmxHel private void populateMemory() { String location = "populateMemory"; try { - Object o = mbsc.getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage"); + Object o = getMBSC().getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage"); CompositeData cd = (CompositeData) o; memoryUsed = (Long) cd.get("used"); memoryMax = (Long) cd.get("max"); @@ -193,7 +185,7 @@ public class BrokerHelper extends JmxHel String location = "populateRuntime"; try { Object o; - o = mbsc.getAttribute(new ObjectName("java.lang:type=Runtime"), "StartTime"); + o = getMBSC().getAttribute(new ObjectName("java.lang:type=Runtime"), "StartTime"); startTime = (Long) o; } catch(Exception e) { @@ -301,7 +293,7 @@ public class BrokerHelper extends JmxHel if(dName.startsWith("ducc.")) { logger.trace(location, jobid, dType+": "+dName); Map<String,String> attributes = new TreeMap<String,String>(); - AttributeList attributeList = mbsc.getAttributes(objectName, topicAttributeNames); + AttributeList attributeList = getMBSC().getAttributes(objectName, topicAttributeNames); for(Object object : attributeList) { Attribute attribute = (Attribute) object; String attrName = attribute.getName(); @@ -335,7 +327,7 @@ public class BrokerHelper extends JmxHel String prefix = "ducc."; if(start(name,prefix)) { Map<String,String> attributes = new TreeMap<String,String>(); - AttributeList attributeList = mbsc.getAttributes(objectName, topicAttributeNames); + AttributeList attributeList = getMBSC().getAttributes(objectName, topicAttributeNames); for(Object object : attributeList) { Attribute attribute = (Attribute) object; String attrName = attribute.getName(); @@ -358,7 +350,7 @@ public class BrokerHelper extends JmxHel private Map<String,Map<String,String>> search() throws IOException, InstanceNotFoundException, ReflectionException { Map<String,Map<String,String>> map = new TreeMap<String,Map<String,String>>(); - Set<ObjectName> objectNames = new TreeSet<ObjectName>(mbsc.queryNames(null, null)); + Set<ObjectName> objectNames = new TreeSet<ObjectName>(getMBSC().queryNames(null, null)); for (ObjectName objectName : objectNames) { brokerAdd(objectName); } @@ -378,7 +370,7 @@ public class BrokerHelper extends JmxHel } String s1 = "Broker"; if(match(s0,s1)) { - AttributeList attributeList = mbsc.getAttributes(objectName, brokerAttributeNames); + AttributeList attributeList = getMBSC().getAttributes(objectName, brokerAttributeNames); for(Object object : attributeList) { Attribute attribute = (Attribute) object; String attrName = attribute.getName(); @@ -419,21 +411,7 @@ public class BrokerHelper extends JmxHel return getJmxPort(); } - private void connect() throws IOException { - jmxServiceUrl = new JMXServiceURL(getJmxUrl()); - jmxc = JMXConnectorFactory.connect(jmxServiceUrl, null); - mbsc = jmxc.getMBeanServerConnection(); - } - private void disconnect() { - String location = "disconnect"; - try { - jmxc.close(); - } - catch(Exception e) { - logger.error(location, jobid, e); - } - } // Operating System Info // @@ -491,17 +469,6 @@ public class BrokerHelper extends JmxHel boolean retVal = DuccDaemonsData.getInstance().isWsPublicationOntime(); return retVal; } - - @Override - protected void reconnect() { - String location = "reconnect"; - try { - jmxConnect(); - } - catch(Exception e) { - logger.error(location, jobid, e); - } - } // Command Line Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/DatabaseHelper.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/DatabaseHelper.java?rev=1852757&r1=1852756&r2=1852757&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/DatabaseHelper.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/DatabaseHelper.java Fri Feb 1 15:39:08 2019 @@ -31,9 +31,12 @@ public class DatabaseHelper extends JmxH private static DuccLogger logger = DuccLogger.getLogger(DatabaseHelper.class); private static DuccId jobid = null; - private static DatabaseHelper instance = new DatabaseHelper(); + private static DatabaseHelper instance = null; public static DatabaseHelper getInstance() { + if(instance == null) { + instance = new DatabaseHelper(); + } return instance; } @@ -54,7 +57,6 @@ public class DatabaseHelper extends JmxH setJmxHost(jmx_host); Integer jmx_port = DbHelper.getJxmPortInteger(); setJmxPort(jmx_port); - jmxConnect(); } } catch(Exception e) { @@ -99,9 +101,10 @@ public class DatabaseHelper extends JmxH } catch(Exception e) { try { - reconnect(); + connect(); mbsc = getMBSC(); o = mbsc.getAttribute(new ObjectName("java.lang:type=Runtime"), "StartTime"); + disconnect(); retVal = (Long) o; } catch(Exception e2) { @@ -111,11 +114,4 @@ public class DatabaseHelper extends JmxH return retVal; } - @Override - protected void reconnect() { - String location = "reconnect"; - init(); - logger.debug(location, jobid, "reconnected"); - } - } Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/JmxHelper.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/JmxHelper.java?rev=1852757&r1=1852756&r2=1852757&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/JmxHelper.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/helper/JmxHelper.java Fri Feb 1 15:39:08 2019 @@ -18,8 +18,6 @@ */ package org.apache.uima.ducc.ws.helper; -import java.io.IOException; - import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; @@ -37,9 +35,9 @@ public abstract class JmxHelper { private String jmxHost = "localhost"; private int jmxPort = -1; - private JMXServiceURL url; - private JMXConnector jmxc; - private MBeanServerConnection mbsc; + private JMXServiceURL url = null; + private JMXConnector jmxc = null; + private MBeanServerConnection mbsc = null; protected void setJmxHost(String value) { jmxHost = value; @@ -65,10 +63,36 @@ public abstract class JmxHelper { return mbsc; } - protected void jmxConnect() throws IOException { - url = new JMXServiceURL(getJmxUrl()); - jmxc = JMXConnectorFactory.connect(url, null); - mbsc = jmxc.getMBeanServerConnection(); + protected void connect() throws Exception { + String location = "connect"; + try { + url = new JMXServiceURL(getJmxUrl()); + jmxc = JMXConnectorFactory.connect(url, null); + mbsc = jmxc.getMBeanServerConnection(); + String id = jmxc.getConnectionId(); + logger.debug(location, jobid, id); + } + catch(Exception e) { + logger.error(location, jobid, e); + throw e; + } + + } + + protected void disconnect() throws Exception { + String location = "disconnect"; + try { + if(jmxc != null) { + String id = jmxc.getConnectionId(); + jmxc.close(); + jmxc = null; + logger.debug(location, jobid, id); + } + } + catch(Exception e) { + logger.error(location, jobid, e); + throw e; + } } protected String getJmxData() throws Exception { @@ -79,9 +103,10 @@ public abstract class JmxHelper { o = mbsc.getAttribute(new ObjectName("java.lang:type=Runtime"), "Name"); } catch(Exception e) { - reconnect(); + connect(); mbsc = getMBSC(); o = mbsc.getAttribute(new ObjectName("java.lang:type=Runtime"), "Name"); + disconnect(); } String data = (String) o; return data; @@ -102,5 +127,4 @@ public abstract class JmxHelper { return retVal; } - protected abstract void reconnect(); }