尝试获取Hazelcast的ManagedExecutorService的属性值,我得到错误ReflectionException。使用JConsole,我可以正常看到值。
String connectionUrl = "service:jmx:http-remoting-jmx://127.0.0.1:9990";
JMXServiceURL url = new JMXServiceURL(connectionUrl);
Map<String, Object> auth = new HashMap<>();
String[] credentials = new String[] {"developer", "developer"};
auth.put (JMXConnector.CREDENTIALS, credentials);
JMXConnector jmxc = JMXConnectorFactory.connect(url, auth);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
try {
ObjectName objectName = new ObjectName("com.hazelcast:instance=_hzInstance_1_dev,name=\"hz:async\","
+ "type=HazelcastInstance.ManagedExecutorService");
MBeanInfo info = mbsc.getMBeanInfo(objectName);
mbsc.getAttribute(objectName, "eventQueueSize"); //exception here
//AttributeList lst =
// mbsc.getAttributes(objectName, new String[]{"eventQueueSize", "completedTaskCount"}); // and here
//System.out.println(lst);
} finally {
jmxc.close();
}
例外:
Exception in thread "main" javax.management.ReflectionException
at com.hazelcast.jmx.HazelcastMBean.getAttribute(HazelcastMBean.java:115)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:647)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:678)
at org.jboss.as.jmx.PluggableMBeanServerImpl$TcclMBeanServer.getAttribute(PluggableMBeanServerImpl.java:1390)
at org.jboss.as.jmx.PluggableMBeanServerImpl.getAttribute(PluggableMBeanServerImpl.java:393)
at org.jboss.as.jmx.BlockingNotificationMBeanServer.getAttribute(BlockingNotificationMBeanServer.java:148)
at org.jboss.remotingjmx.protocol.v2.ServerProxy$GetAttributeHandler.handle(ServerProxy.java:691)
at org.jboss.remotingjmx.protocol.v2.ServerCommon$MessageReciever$1$1.run(ServerCommon.java:153)
at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor$1.run(ServerInterceptorFactory.java:75)
at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor$1.run(ServerInterceptorFactory.java:70)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:94)
at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor.handleEvent(ServerInterceptorFactory.java:70)
at org.jboss.remotingjmx.protocol.v2.ServerCommon$MessageReciever$1.run(ServerCommon.java:149)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
答案 0 :(得分:2)
我认为您应该尝试在queueSize
类中定义的ManagedExecutorServiceMBean
:
@ManagedAnnotation("queueSize")
@ManagedDescription("The work queue size")
public int queueSize() {
return managedObject.getQueueSize();
}
答案 1 :(得分:1)
您确定属性名称是eventQueueSize而不是EventQueueSize?