Package java.lang.management

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.

See:
          Description

Interface Summary
ClassLoadingMBean The management interface for the class loading system of the Java virtual machine.
CompilationMBean The management interface for the compilation system of the Java virtual machine.
GarbageCollectorMBean The management interface for the garbage collection of the Java virtual machine.
MemoryManagerMBean The management interface for a memory manager.
MemoryMBean The management interface for the memory system of the Java virtual machine.
MemoryPoolMBean The management interface for a memory pool.
OperatingSystemMBean The management interface for the operating system on which the Java virtual machine is running.
RuntimeMBean The management interface for the runtime system of the Java virtual machine.
ThreadMBean The management interface for the thread system of the Java virtual machine.
 

Class Summary
ManagementFactory ManagementFactory class is a factory class for getting managed beans for the Java platform.
ManagementPermission The permission which the SecurityManager will check when code that is running with a SecurityManager calls methods defined in the management interface for the Java platform.
MemoryNotification A memory notification emitted by MemoryMBean indicating that the Java virtual machine detects that the memory usage of a memory pool is crossing a threshold value.
MemoryUsage A MemoryUsage object represents a snapshot of memory usage.
ThreadInfo Thread information.
 

Enum Summary
MemoryType Types of memory pools.
ThreadState Possible states of a thread running in the Java virtual machine.
 

Package java.lang.management Description

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 monitoring and management of the running Java virtual machine.

MBeans (Managed Beans)

This package defines the management interface of the following components:
Management Interface Description
ClassLoadingMBean Class loading system of the Java virtual machine.
CompilationMBean Compilation system of the Java virtual machine.
MemoryMBean Memory system of the Java virtual machine.
ThreadMBean Threads system of the Java virtual machine.
RuntimeMBean Runtime system of the Java virtual machine.
OperatingSystemMBean Operating system on which the Java virtual machine is running.
GarbageCollectorMBean Garbage collector in the Java virtual machine.
MemoryManagerMBean Memory manager in the Java virtual machine.
MemoryPoolMBean Memory pool in the Java virtual machine.

The object that implements the management interface is a managed bean (MBean) that conforms to the JMX Instrumentation Specification. An application can monitor the instrumentation of the Java virtual machine and manage certain characteristics in any of the following ways:

Below shows a few examples of different ways to access management metrics.

ManagementFactory

The ManagementFactory class is the management factory class for the Java platform. This class provides a set of static factory methods to obtain the MBeans for the Java platform to allow an application to access the MBeans directly.

This class provides the ManagementFactory.getPlatformMBeanServer() method to create the platform MBeanServer and register all platform MBeans into the platform MBeanServer. Each MBean is registered with a unique defined ObjectName.

Platform Extension

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.

Ways to Access Management Metrics

There are three different ways to access the management metrics.

  1. Call the methods in the MBean directly within the same Java virtual machine.
       RuntimeMBean mbean = ManagementFactory.getRuntimeMBean();
    
       // Get the standard attribute "VmVendor"
       String vendor = mbean.getVmVendor();
    
    
  2. Go through the MBeanServer.
  3.    MBeanServerConnection mbs;
    
       // Connect to a running JVM (or itself) and get MBeanServerConnection
       // that has the JVM MBeans registered in it
       ...
    
       try {
           // Assuming the RuntimeMBean has been registered in mbs
           ObjectName oname = new ObjectName(MBeanNames.RUNTIME_MBEAN);
        
           // Get standard attribute "VmVendor"
           String vendor = (String) mbs.getAttribute(oname, "VmVendor");
       } catch (....) {
           // Catch the exceptions thrown by ObjectName constructor
           // and MBeanServer.getAttribute method
           ...
       }
    
    
  4. Use MBean proxy.
  5.    MBeanServerConnection mbs;
    
       // Connect to a running JVM (or itself) and get MBeanServerConnection
       // that has the JVM MBeans registered in it
       ...
    
       // Assuming the RuntimeMBean has been registered in mbs
       ObjectName oname = new ObjectName(MBeanNames.RUNTIME_MBEAN);
    
       // Get a MBean proxy for RuntimeMBean interface
       RuntimeMBean proxy = (RuntimeMBean)
           MBeanServerInvocationHandler.newProxyInstance(mbs,
                                                         oname,
                                                         RuntimeMBean.class,
                                                         false);
       // Get standard attribute "VmVendor" 
       String vendor = proxy.getVmVendor();
    

Platform-Specific Attribute Names

It is recommended to name the platform-specific attributes with a vendor-specific prefix such as the name of virtual machine to avoid collisions of the attribute name between the future extension to the standard management interface and the platform extension. If the future extension to the standard management interface defines a new attribute for a management interface and the attribute name is happened to be same as some vendor-specific attribute's name, the applications accessing that vendor-specific attribute would have to be modified to cope with versioning and compatibility issues.

Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

Since:
1.5