java.lang.management

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » lang » java.lang.management 
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. 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:

  • Direct access to an MXBean interface
    1. Get the MXBean instance through the static factory method and access the MXBean interface locally of the running virtual machine.
    2. Construct an MXBean proxy instance that forwards the method calls to a given {@link javax.management.MBeanServer MBeanServer} by calling {@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy ManagementFactory.newPlatformMXBeanProxy}. A proxy is typically constructed to remotely access an MXBean of another running virtual machine.
  • Indirect access via {@link javax.management.MBeanServer MBeanServer} interface
    1. Go through the {@link java.lang.management.ManagementFactory#getPlatformMBeanServer platform MBeanServer} to access MXBeans locally or a specific MBeanServerConnection to access MXBeans remotely. The attributes and operations of an MXBean use only JMX open types which include basic data types, {@link javax.management.openmbean.CompositeData CompositeData}, and {@link javax.management.openmbean.TabularData TabularData} defined in {@link javax.management.openmbean.OpenType OpenType}.
Below shows a few examples of different ways to access MXBeans.

ManagementFactory

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.

A platform MBeanServer can be accessed with the {@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}. 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 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 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. 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.

  1. Call the methods in the MXBean directly within the same Java virtual machine.
       RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
    
       // Get the standard attribute "VmVendor"
       String vendor = mxbean.getVmVendor();
    
    
  2. Go through a MBeanServerConnection connecting to the platform MBeanServer of a running virtual machine.
  3.    MBeanServerConnection mbs;
    
       // Connect to a running JVM (or itself) and get MBeanServerConnection
       // 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");
       } catch (....) {
           // Catch the exceptions thrown by ObjectName constructor
           // and MBeanServer.getAttribute method
           ...
       }
    
    
  4. Use MXBean proxy.
  5.    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 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.

It is recommended to name the platform-specific attributes with a vendor-specific prefix such as the vendor's name 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.

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

1) Direct access to the Sun-specific MXBean interface

   com.sun.management.RuntimeMXBean mxbean = 
       (com.sun.management.RuntimeMXBean) ManagementFactory.getRuntimeMXBean();

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

   // Get the platform-specific attribute "Bar"
   BarType bar = mxbean.getBar();

2) Access the Sun-specific MXBean interface via MBeanServer

   MBeanServerConnection mbs;

   // Connect to a running JVM (or itself) and get MBeanServerConnection
   // 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");

       // 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
       ...
   }

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

The java.lang.management API is thread-safe. @see JMX Specification. @author Mandy Chung @version 1.17, 05/05/07 @since 1.5

Java Source File NameTypeComment
ClassLoadingMXBean.javaInterface The management interface for the class loading system of the Java virtual machine.
CompilationMXBean.javaInterface The management interface for the compilation system of the Java virtual machine.

A Java virtual machine has a single instance of the implementation class of this interface.

GarbageCollectorMXBean.javaInterface The management interface for the garbage collection of the Java virtual machine.
LockInfo.javaClass Information about a lock.
ManagementFactory.javaClass The ManagementFactory class is a factory class for getting managed beans for the Java platform. This class consists of static methods each of which returns one or more platform MXBean(s) representing the management interface of a component of the Java virtual machine.
ManagementPermission.javaClass 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.

The following table provides a summary description of what the permission allows, and discusses the risks of granting code the permission.

Permission Target Name What the Permission Allows Risks of Allowing this Permission
control Ability to control the runtime characteristics of the Java virtual machine, for example, setting the -verbose:gc and -verbose:class flag, setting the threshold of a memory pool, and enabling and disabling the thread contention monitoring support.
MemoryManagerMXBean.javaInterface The management interface for a memory manager.
MemoryMXBean.javaInterface The management interface for the memory system of the Java virtual machine.

A Java virtual machine has a single instance of the implementation class of this interface.

MemoryNotificationInfo.javaClass The information about a memory notification.

A memory notification is emitted by MemoryMXBean when the Java virtual machine detects that the memory usage of a memory pool is exceeding a threshold value.

MemoryPoolMXBean.javaInterface The management interface for a memory pool.
MemoryType.javaenum Types of MemoryPoolMXBean memory pools .
MemoryUsage.javaClass A MemoryUsage object represents a snapshot of memory usage. Instances of the MemoryUsage class are usually constructed by methods that are used to obtain memory usage information about individual memory pool of the Java virtual machine or the heap or non-heap memory of the Java virtual machine as a whole.

A MemoryUsage object contains four values:

    init represents the initial amount of memory (in bytes) that the Java virtual machine requests from the operating system for memory management during startup.
    MonitorInfo.javaClass Information about an object monitor lock.
    OperatingSystemMXBean.javaInterface The management interface for the operating system on which the Java virtual machine is running.

    A Java virtual machine has a single instance of the implementation class of this interface.

    RuntimeMXBean.javaInterface The management interface for the runtime system of the Java virtual machine.

    A Java virtual machine has a single instance of the implementation class of this interface.

    ThreadInfo.javaClass Thread information.
    ThreadMXBean.javaInterface The management interface for the thread system of the Java virtual machine.

    A Java virtual machine has a single instance of the implementation class of this interface.

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.