Unexpected behavior from JMX.newMBeanProxy()

182 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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);