我有以下代码,仅列出了平台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)

08-03 21:42