gpt4 book ai didi

java - 如何初始化 JRockit MBean 树

转载 作者:行者123 更新时间:2023-12-01 15:33:08 24 4
gpt4 key购买 nike

我有以下代码,仅列出在平台 MBean 服务器中找到的所有 MBean 名称:

  public static void main(final String[] args) throws Exception {

initJMX();

}

@SuppressWarnings("unchecked")
private static void initJMX() throws IOException, MalformedURLException, AttributeNotFoundException,
InstanceNotFoundException, MalformedObjectNameException, MBeanException, ReflectionException,
NullPointerException {
JMXConnector jmxc = null;
final Map<String, String> map = new HashMap<String, String>();
jmxc = JMXConnectorFactory.newJMXConnector(createConnectionURL("localhost", 7788), map);
jmxc.connect();
final MBeanServerConnection connection = jmxc.getMBeanServerConnection();
final String[] domains = connection.getDomains();
for (final String domain : domains) {
final Set<ObjectName> mBeans = connection.queryNames(new ObjectName(domain + ":*"), null);
for (final ObjectName name : mBeans) {
System.out.println(name);
}
}
jmxc.close();
}

当我尝试使用 JRockit 1.5.0_4.0.1 并使用以下参数运行此代码时:

-Xmanagement:ssl=false,authenticate=false,autodiscovery=false,port=7788

它会打印以下列表:

[INFO ][mgmnt  ] Remote JMX connector started at address localhost:7788 
[INFO ][mgmnt ] Local JMX connector started
com.oracle.jrockit:type=FlightRecorder
java.util.logging:type=Logging
JMImplementation:type=MBeanServerDelegate
java.lang:type=Compilation
java.lang:type=GarbageCollector,name=Garbage collection optimized for throughput Young Collector
java.lang:type=MemoryManager,name=Class Manager
java.lang:type=MemoryPool,name=ClassBlock Memory
java.lang:type=GarbageCollector,name=Garbage collection optimized for throughput Old Collector
java.lang:type=Runtime
java.lang:type=MemoryPool,name=Nursery
java.lang:type=ClassLoading
java.lang:type=Threading
java.lang:type=MemoryPool,name=Class Memory
java.lang:type=OperatingSystem
java.lang:type=Memory
java.lang:type=MemoryPool,name=Old Space

但是,如果我在调用 initJMX 方法之前放置一个断点,然后使用 JRMC 连接到该 JVM,那么 JRMC 会显示更多的 MBean,并且在我继续执行程序后,它还会打印一个不同的列表,其中包含更多与 JRockit 相关的列表MBean:

[INFO ][mgmnt  ] Remote JMX connector started at address T500W7AAD:7788 
[INFO ][mgmnt ] Local JMX connector started
com.oracle.jrockit:type=FlightRecorder
oracle.jrockit.management:type=PerfCounters
oracle.jrockit.management:type=Compilation
oracle.jrockit.management:type=Log
oracle.jrockit.management:type=Profiler
oracle.jrockit.management:type=MemLeak
oracle.jrockit.management:type=JRockitConsole
oracle.jrockit.management:type=GarbageCollector
oracle.jrockit.management:type=Runtime
oracle.jrockit.management:type=Threading
oracle.jrockit.management:type=DiagnosticCommand
oracle.jrockit.management:type=Memory
java.util.logging:type=Logging
JMImplementation:type=MBeanServerDelegate
java.lang:type=Compilation
java.lang:type=GarbageCollector,name=Garbage collection optimized for throughput Young Collector
java.lang:type=MemoryManager,name=Class Manager
java.lang:type=MemoryPool,name=ClassBlock Memory
java.lang:type=GarbageCollector,name=Garbage collection optimized for throughput Old Collector
java.lang:type=Runtime
java.lang:type=MemoryPool,name=Nursery
java.lang:type=ClassLoading
java.lang:type=Threading
java.lang:type=MemoryPool,name=Class Memory
java.lang:type=OperatingSystem
java.lang:type=Memory
java.lang:type=MemoryPool,name=Old Space

有没有办法让 JRockit 在 JVM 启动时自动初始化这些 bean,而不需要显式 JRMC 连接?问题是我正在尝试编写一些重用其中一些 MBean 的代码,但在我连接 JRMC 之前它们不可用。

更新:这似乎是 JRockit jdk1.5.0_4.0.1 问题。相同的代码在 JRockit jdk6.0_4.1.0 上按预期工作。

最佳答案

这似乎是我使用的 Windows 版本的 JRockit 的问题:

java version "1.5.0_24"
Java(TM) Platform, Standard Edition for Business (build 1.5.0_24-b02)
Oracle JRockit(R) (build R28.0.1-21-133393-1.5.0_24-20100512-2131-windows-x86_64, compiled mode)

相同的代码在 Windows 上的最新 JRockit for JDK 1.6.0 上按预期工作:

java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Oracle JRockit(R) (build R28.2.2-7-148152-1.6.0_29-20111221-2104-windows-x86_64, compiled mode)

并且在相同的 JRockit 版本上,但针对 Linux:

java version "1.5.0_24"
Java(TM) Platform, Standard Edition for Business (build 1.5.0_24-b02)
Oracle JRockit(R) (build R28.1.0-123-138454-1.5.0_24-20101014-1350-linux-x86_64, compiled mode)

关于java - 如何初始化 JRockit MBean 树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9324186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com