问题
I can see that some methods on the jconsole are disabled.
Given below is the screenshot for com.sun.management.ThreadMXBean
The javadocs for these MBean methods do not specify anything about the accessibility part.
I think it is a security feature, but I am not able to get a concrete answer for this.
The obvious second part to this question is how to create custom MBean implementations which can be selectively disabled on the jconsole.
Given below is the system config :
JConsole version "1.7.0-b147"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)
EDIT :
The disabled methods are invokable from a stand alone process.
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("java.lang", "type", "Threading");
String operationName = "getThreadAllocatedBytes";
//1 is main thread
Object[] params = {1};
String[] signature = new String[]{"long"};
Object result = server.invoke(name, operationName, params, signature);
//Result is 682760 on my machine
System.out.println(result);
回答1:
The reason is a little more benign, they are enabled only for operations which take in simple types - int or string. The disabled operations take in more complex types like arrays ( there is no facility to take in complex types, and nothing like say a Spring property editor which can convert a string to a complex type)
Here is a related question: Websphere 7.X. JMX, how to enable all operations in JConsole?
Update: This is based on looking at the source code for JConsole from the OpenJDK site http://hg.openjdk.java.net/jdk7u/jdk7u, the operations are enabled or disabled based on the method signature and this is encapsulated in the method - sun.tools.jconsole.inspector.Utils.isEditable(String type)
. The allowed types are primitives, primitives wrappers, array of primitives,
来源:https://stackoverflow.com/questions/12025003/why-are-some-methods-on-the-jconsole-disabled