java.lang:type=threading mbean
There is a very useful mbean under java.lang called, java.lang:type=threading (as viewed from jConsole). I wish to invoke it's getThreadInfo operation. As I understand it, the easy way to do this is via a proxy as in:
newProxyInstance(MBeanServerConnection connection,
ObjectName objectName,
Class interfaceClass,
boolean notificationBroadcaster)
The harder way is to use the mbean connection invoke method, ie
invoke(ObjectName name,
String operationName,
Object[] params,
String[] signature)
Questions:
1) What is the interfaceClass of this mbean and how do you find these interface class names?
2) If the easy way is not possible then how does one construct the signature for getThreadInfo(int p0):CompositeData? Is it as simple as "new String[] {int.class}"?
Jeff
A jmx Newbe
It's in the java.lang.management package that can be accessed locally within your application and also remotely via JMX technology. The Java SE monitoring and management documentation is at:
http://java.sun.com/javase/6/docs/technotes/guides/management/index.html
You can also reference the sample code from JDK/demo/management on the usage of the java.lang.management API.
Thanks for the help but can you answer the specific questions, ie proxy for the threading mbean? Or maybe the question doesn't make sense? Also, we are not using java 6 yet, so I need a java 5 solution.Jeff
Do you want to call getThreadInfo remotely or call it locally?
To obtain an instance of ThreadMXBean remotely, call
ManagementFactory.newPlatformMXBeanProxy(mbs,
THREAD_MXBEAN_NAME,
ThreadMXBean.class);
To obtain an instance of ThreadMXBean locally, call
ManagementFactory.getThreadMXBean()
Both return an instance of ThreadMXBean and then you can call getThreadInfo method. See
http://java.sun.com/javase/6/docs/api/java/lang/management/ManagementFactory.html
<JDK>/demo/management/FullThreadDump demonstrates how to do that.
Hope this helps.