Previous | Contents | Next |
Chapter 1 Overview of Java SE Monitoring and ManagementThis chapter introduces the features and utilities that provide monitoring and management services to the Java Platform, Standard Edition (Java SE platform). The features introduced here will be expanded upon in the following chapters of this guide. Key Monitoring and Management FeaturesThe Java SE platform includes significant monitoring and management features. These features fall into four broad categories.
These categories of monitoring and management features are introduced further in the next sections. Java VM InstrumentationThe Java VM is instrumented for monitoring and management, enabling built-in (or out-of-the-box) management capabilities that can be accessed both remotely and locally. For more information, see Chapter 2, Monitoring and Management Using JMX Technology and Chapter 5, SNMP Monitoring and Management. The Java VM includes a platform MBean server and platform MBeans for use by management applications that conform to the JMX specification. These are implementations of the monitoring and management API described in the next section. Platform MXBeans and MBean servers are introduced in Platform MXBeans and Platform MBean Server. Example code is provided in the JDK_HOME/demo/management directory, where JDK_HOME is the directory in which the Java Development Kit (JDK) is installed. Monitoring and Management APIThe java.lang.management package provides the interface for monitoring and managing the Java VM. This API provides access to the following types of information.
In addition to the java.lang.management API, the java.util.logging.LoggingMXBean API provides allows you to perform monitoring and management of logging. Monitoring and Management ToolsThe Java SE platform provides a graphical monitoring tool called JConsole. JConsole implements the JMX API and enables you to monitor the performance of a Java VM and any instrumented applications, by providing information to help you optimize performance. Introduced in the Java SE platform 5.0, JConsole became an officially supported feature of the platform in the Java SE 6. Some of the enhancements that have been made to JConsole between these two releases of the Java SE platform are as follows.
JConsole is presented in full in Chapter 3, Using JConsole. Other command-line tools are also supplied with the Java SE platform. See the Monitoring Tools section of the JDK Development Tools document for more information. Java Management Extensions (JMX) TechnologyThe Java SE platform, version 8 includes the JMX specification, version 1.4. The JMX API allows you to instrument applications for monitoring and management. An RMI connector allows this instrumentation to be remotely accessible, for example by JConsole. For more information, see the JMX technology documentation for the Java SE platform. A very brief introduction to the main components of the JMX API is included in the next sections. What are MBeans?JMX technology MBeans are managed beans, namely Java objects that represent resources to be managed. An MBean has a management interface consisting of the following.
For example, an MBean representing an application's configuration could have attributes representing different configuration parameters, such as a cache size. Reading the CacheSize attribute would return the current size of the cache. Writing CacheSize would update the size of the cache, potentially changing the behavior of the running application. An operation such as save could store the current configuration persistently. The MBean could send a notification such as ConfigurationChangedNotification when the configuration changes. MBeans can be standard or dynamic. Standard MBeans are Java objects that conform to design patterns derived from the JavaBeans component model. Dynamic MBeans define their management interface at runtime. More recently, an additional type of MBean called an MXBean has also been added to the Java platform.
MBean ServerTo be useful, an MBean must be registered in an MBean server. An MBean Server is a repository of MBeans. Each MBean is registered with a unique name within the MBean server. Usually the only access to the MBeans is through the MBean server. In other words, code does not access an MBean directly, but rather accesses the MBean by name through the MBean server. The Java SE platform includes a built-in platform MBean server. For more information, see Chapter 4, Using the Platform MBean Server and Platform MXBeans. Creating and Registering MBeansThere are two ways to create an MBean. One is to construct a Java object that will be the MBean, then use the registerMBean method to register it in the MBean Server. The other is to create and register the MBean in a single operation using one of the createMBean methods. The registerMBean method is simpler for local use, but cannot be used remotely. The createMBean method can be used remotely, but sometimes requires attention to class loading issues. An MBean can perform actions when it is registered in or unregistered from an MBean Server if it implements the MBeanRegistration interface. Instrumenting ApplicationsGeneral instructions on how to instrument your applications for management by the JMX API is beyond the scope of this document. See the documentation for the Java Management Extensions (JMX) Technology for information. Platform MXBeansA platform MXBean is an MBean for monitoring and managing the Java VM and other components of the Java Runtime Environment (JRE). Each MXBean encapsulates a part of VM functionality such as the class loading system, just-in-time (JIT) compilation system, garbage collector, and so on. Table 1-1 lists all the platform MXBeans and the aspect of the VM that they manage. Each platform MXBean has a unique javax.management.ObjectName for registration in the platform MBean server. A Java VM may have zero, one, or more than one instance of each MXBean, depending on its function, as shown in the table. Table 1-1 Platform MXBeans
See the package description in the API reference for the java.lang.management package for details of the platform MXBeans (apart from LoggingMXBean). See the API reference for java.util.logging for details of the LoggingMXBean. Platform MBean ServerThe platform MBean Server can be shared by different managed components running within the same Java VM. You can access the platform MBean Server with the method ManagementFactory.getPlatformMBeanServer(). The first call to this method, creates the platform MBean server and registers the platform MXBeans using their unique object names. Subsequently, it returns the initially created platform MBeanServer instance. MXBeans that are created and destroyed dynamically (for example, memory pools and managers) will automatically be registered and unregistered in the platform MBean server. If the system property javax.management.builder.initial is set, the platform MBean server will be created by the specified MBeanServerBuilder. You can use the platform MBean server to register other MBeans besides the platform MXBeans. This enables all MBeans to be published through the same MBean server and makes network publishing and discovery easier. | ||||||||||||||||||||||||||||||||||||||||||||
|