为什么JConsole上的某些方法被禁用 [英] Why are some methods on the JConsole disabled

查看:150
本文介绍了为什么JConsole上的某些方法被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以看到 jconsole 上的某些方法被禁用。

I can see that some methods on the jconsole are disabled.

下面是 com的屏幕截图.sun.management.ThreadMXBean

javadocs 没有指定任何有关可访问性部分的内容。

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.

这个问题的第二部分显然是如何创建自定义MBean实现可以在jconsole上有选择地禁用它。

The obvious second part to this question is how to create custom MBean implementations which can be selectively disabled on the jconsole.

以下是系统配置:


JConsole版本1.7.0-b147

JConsole version "1.7.0-b147"

Java(TM)SE运行时环境(版本1.7.0-b147)

Java(TM) SE Runtime Environment (build 1.7.0-b147)

Java HotSpot(TM)6 4位服务器VM(版本21.0-b17,混合模式)

Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

编辑

禁用的方法可以从独立进程中调用。

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


推荐答案

原因是更温和,它们已启用仅适用于采用简单类型的操作 - int或string。禁用的操作采用更复杂的类型,如数组(没有设施可以采用复杂的类型,没有像弹簧属性编辑器那样可以将字符串转换为复杂类型)

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)

以下是一个相关问题: Websphere 7.X. JMX,如何在JConsole中启用所有操作?

Here is a related question: Websphere 7.X. JMX, how to enable all operations in JConsole?

更新:这是基于查看JConsole的源代码OpenJDK网站 http://hg.openjdk.java.net/jdk7u/jdk7u ,根据方法签名启用或禁用操作,并将其封装在方法 - sun.tools.jconsole.inspector.Utils.isEditable(String type)中。允许的类型是基元,基元包装器,基元数组,

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,

这篇关于为什么JConsole上的某些方法被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆