Search code examples
javajmxmbeansmxbean

Unexpected behavior from JMX.newMBeanProxy()


I get a ThreadMXBean proxy for remote JVM as

 ObjectName objName = ManagementFactory.getThreadMXBean().getObjectName() ;


  ThreadMXBean proxy = JMX.newMBeanProxy(MBeanServerConnection, objName, ThreadMXBean.class);

However, when I call the following, it says it can't convert from CompositeDataSupport to ThreadInfo.

 ThreadInfo tInfo = proxy. getThreadInfo(true, true);

Shouldn't the proxy take care of all the conversion? Besides, I'm calling the getThreadInfo() on effectively ThreadMXBean.


Solution

  • ThreadMXBean is an MXBean. Your code has called JMX#newMBeanProxy. The proxy returned by this method is not capable of handling the properties of MXBeans. Instead, use JMX#newMXBeanFactory to obtain a proxy capable of handling the properties of MXBeans.

    ThreadMXBean proxy = JMX.newMXBeanProxy(MBeanServerConnection, objName, ThreadMXBean.class);