我正在尝试从作者实例获取发布服务器的HeapMemoryUsage
。
我附上了下面调用的servlet的代码。
在例外中,您可以看到我们在第88行获得NullPointerException
JMXConnectorFactory.connect(serviceUrl)
。
从Jconsole或从测试类(使用main方法本地)运行它,它的运行没有任何问题。
例外:
29.11.2012 15:01:17.407 *ERROR* [127.0.0.1 [1354197677403] GET /bin/cqdashboard HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.NullPointerException
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2327)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:277)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at com.test.cq.dashboard.servlet.DashboardTestServlet.doGet(DashboardTestServlet.java:88)
.....
守则:
String jmxUrl = "service:jmx:rmi:///jndi/rmi://127.0.0.1:43004/jmxrmi";
JMXServiceURL serviceUrl = new JMXServiceURL(jmxUrl);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl);
MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
ObjectName on = new ObjectName("java.lang:type=Memory");
CompositeData cd = (CompositeData) mbeanConn.getAttribute(on, "HeapMemoryUsage");
response.getWriter().write(cd.get("used"));
// System.out.println(cd.get("used"));
非常感谢