--- old/src/share/classes/java/lang/management/package.html Mon Mar 28 11:54:18 2011 +++ new/src/share/classes/java/lang/management/package.html Mon Mar 28 11:54:17 2011 @@ -27,108 +27,24 @@ -Provides the management interface for monitoring and management of the -Java virtual machine as well as the operating system on which the -Java virtual machine is running. It allows both local and remote +Provides the management interfaces for monitoring and management of the +Java virtual machine and other components in the Java runtime. +It allows both local and remote monitoring and management of the running Java virtual machine. - -

Platform MXBeans

- -This package defines the management interface of the following -components: - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Management Interface

Description

{@link java.lang.management.ClassLoadingMXBean} Class loading system of the Java virtual machine.
{@link java.lang.management.CompilationMXBean} Compilation system of the Java virtual machine.
{@link java.lang.management.MemoryMXBean} Memory system of the Java virtual machine.
{@link java.lang.management.ThreadMXBean} Threads system of the Java virtual machine.
{@link java.lang.management.RuntimeMXBean} Runtime system of the Java virtual machine.
{@link java.lang.management.OperatingSystemMXBean} Operating system on which the Java virtual machine is running.
{@link java.lang.management.GarbageCollectorMXBean} Garbage collector in the Java virtual machine.
{@link java.lang.management.MemoryManagerMXBean} Memory manager in the Java virtual machine.
{@link java.lang.management.MemoryPoolMXBean} Memory pool in the Java virtual machine.
-
-

-A platform MXBean is a managed bean that defines the management -interface for one component for the platform and is specified in the - -ManagementFactory class. -

An application can monitor the instrumentation of the -Java virtual machine and manage certain characteristics in -the following ways: -

- -Below shows a few examples of different -ways to access MXBeans. - +

Platform MXBean

+

+A platform MXBean is a managed bean that +conforms to the JMX +Instrumentation Specification and only uses a set of basic data types. +Each platform MXBean is a {@link java.lang.management.PlatformManagedObject} +with a unique +{@linkplain java.lang.management.PlatformManagedObject#getObjectName name}. +

ManagementFactory

-The {@link java.lang.management.ManagementFactory} class is the management +

The {@link java.lang.management.ManagementFactory} class is the management factory class for the Java platform. This class provides a set of static factory methods to obtain the MXBeans for the Java platform to allow an application to access the MXBeans directly. @@ -137,50 +53,98 @@ {@link java.lang.management.ManagementFactory#getPlatformMBeanServer getPlatformMBeanServer} method. On the first call to this method, it creates the platform MBeanServer and registers all platform MXBeans -including platform MXBeans defined in other packages such as -{@link java.util.logging.LoggingMXBean}. -Each platform MXBean is registered with a unique name defined in the -{@link java.lang.management.ManagementFactory ManagementFactory} class -for constructing {@link javax.management.ObjectName ObjectName}. +including {@linkplain java.lang.management.PlatformManagedObject +platform MXBeans}. +Each platform MXBean is registered with a unique name defined in +the specification of the management interface. This is a single MBeanServer that can be shared by different managed components running within the same Java virtual machine.

Interoperability

-A management application and a platform MBeanServer of a running +

A management application and a platform MBeanServer of a running virtual machine can interoperate without requiring classes used by the platform MXBean interfaces. The data types being transmitted between the JMX connector server and the connector client are JMX -{@link javax.management.openmbean.OpenType open types} and +{@linkplain javax.management.openmbean.OpenType open types} and this allows interoperation across versions. +A data type used by the MXBean interfaces are mapped to an +open type when being accessed via MBeanServer interface. +See the +MXBean specification for details. -

A data type used by the MXBean interfaces are mapped to -an open type when being accessed via MBeanServer interface. -The data type mapping is specified in the -{@link java.lang.management.ManagementFactory ManagementFactory} class. -

Ways to Access MXBeans

-There are three different ways to access the management interfaces. - +

An application can monitor the instrumentation of the +Java virtual machine and the runtime in the following ways:

-

    -
  1. Call the methods in the MXBean directly within the same - Java virtual machine. -
    +1. Direct access to an MXBean interface
    +

    +

      +
    • Get an MXBean instance locally in the running Java virtual machine:

      +

          RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
       
          // Get the standard attribute "VmVendor"
          String vendor = mxbean.getVmVendor();
      +
      +

      Or by calling the + {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class) + getPlatformMXBean} or + {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class) + getPlatformMXBeans} method: +

      +   RuntimeMXBean mxbean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class);
       
      +   // Get the standard attribute "VmVendor"
      +   String vendor = mxbean.getVmVendor();
       
      -
    +

  2. +
  3. Construct an MXBean proxy instance that forwards the + method calls to a given MBeanServer:

    +

    +   MBeanServerConnection mbs;
     
    -
  4. Go through a MBeanServerConnection connecting - to the platform MBeanServer of a running virtual machine.
  5. -
    +   // Connect to a running JVM (or itself) and get MBeanServerConnection
    +   // that has the JVM MBeans registered in it
    +   ...
    +
    +   // Get a MBean proxy for RuntimeMXBean interface
    +   RuntimeMXBean proxy = 
    +       {@link java.lang.management.ManagementFactory#getPlatformMXBean(MBeanServerConnection, Class)
    +       ManagementFactory.getPlatformMXBean}(mbs,
    +                                           RuntimeMXBean.class);
    +   // Get standard attribute "VmVendor" 
    +   String vendor = proxy.getVmVendor();
    +
    +

    A proxy is typically used to access an MXBean + in a remote Java virtual machine. + An alternative way to create an MXBean proxy is: +

    +   RuntimeMXBean proxy = 
    +       {@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy
    +              ManagementFactory.newPlatformMXBeanProxy}(mbs,
    +                                                ManagementFactory.RUNTIME_MXBEAN_NAME,
    +                                                RuntimeMXBean.class);
    +
    +
  6. + +

    +2. Indirect access to an MXBean interface via MBeanServer

    +

    - -
  7. Use MXBean proxy.
  8. -
    -   MBeanServerConnection mbs;
    -
    -   // Connect to a running JVM (or itself) and get MBeanServerConnection
    -   // that has the JVM MBeans registered in it
    -   ...
    -
    -   // Get a MBean proxy for RuntimeMXBean interface
    -   RuntimeMXBean proxy = 
    -       ManagementFactory.newPlatformMXBeanProxy(mbs,
    -                                                ManagementFactory.RUNTIME_MXBEAN_NAME,
    -                                                RuntimeMXBean.class);
    -   // Get standard attribute "VmVendor" 
    -   String vendor = proxy.getVmVendor();
    -
    -
- -

Platform Extension

-A Java virtual machine implementation may add its platform extension to +

A Java virtual machine implementation may add its platform extension to the management interface by defining platform-dependent interfaces that extend the standard management interfaces to include platform-specific metrics and management operations. The static factory methods in the ManagementFactory class will -return the MBeans with the platform extension. +return the MXBeans with the platform extension.

It is recommended to name the platform-specific attributes with @@ -240,26 +187,30 @@ the applications accessing that vendor-specific attribute would have to be modified to cope with versioning and compatibility issues. -

Below is an example showing how to access a platform-specific -attribute from Sun's implementation of the RuntimeMXBean. +

Below is an example showing how to access an attribute +from the platform extension:

-1) Direct access to the Sun-specific MXBean interface -

-   com.sun.management.RuntimeMXBean mxbean = 
-       (com.sun.management.RuntimeMXBean) ManagementFactory.getRuntimeMXBean();
+1) Direct access to the Oracle-specific MXBean interface
+
+
+   List<com.sun.management.GarbageCollectorMXBean> mxbeans = 
+       ManagementFactory.getPlatformMXBeans(com.sun.management.GarbageCollectorMXBean.class);
 
-   // Get the standard attribute "VmVendor"
-   String vendor = mxbean.getVmVendor();
+   for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
+       // Get the standard attribute "CollectionCount"
+       String count = mxbean.getCollectionCount();
 
-   // Get the platform-specific attribute "Bar"
-   BarType bar = mxbean.getBar();
-
+       // Get the platform-specific attribute "LastGcInfo"
+       GcInfo gcinfo = gc.getLastGcInfo();
+       ...
+   }
 

-2) Access the Sun-specific MXBean interface via MBeanServer +2) Access the Oracle-specific MXBean interface via MBeanServer + through proxy

    MBeanServerConnection mbs;
@@ -268,24 +219,18 @@
    // that has the JVM MXBeans registered in it
    ...
 
-   try {
-       // Assuming the RuntimeMXBean has been registered in mbs
-       ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
-    
-       // Get standard attribute "VmVendor"
-       String vendor = (String) mbs.getAttribute(oname, "VmVendor");
+   List<com.sun.management.GarbageCollectorMXBean> mxbeans = 
+       ManagementFactory.getPlatformMXBeans(mbs, com.sun.management.GarbageCollectorMXBean.class);
 
-       // Check if this MXBean contains Sun's extension
-       if (mbs.isInstanceOf(oname, "com.sun.management.RuntimeMXBean")) {
-           // Get platform-specific attribute "Bar"
-           BarType bar = (String) mbs.getAttribute(oname, "Bar");
-       }
-   } catch (....) {
-       // Catch the exceptions thrown by ObjectName constructor
-       // and MBeanServer methods
+   for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
+       // Get the standard attribute "CollectionCount"
+       String count = mxbean.getCollectionCount();
+
+       // Get the platform-specific attribute "LastGcInfo"
+       GcInfo gcinfo = gc.getLastGcInfo();
        ...
    }
-
+    
 

Unless otherwise noted, passing a null argument to a constructor