Sunday, July 5, 2009

Java MBean - JVM Monitoring and Management

http://java.sun.com/j2se/1.5.0/docs/guide/management/overview.html

Monitoring and Management Using JMX:
Java Management Extensions (JMX):
http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html


Monitoring and Management APIs

The java.lang.management package provides the interface for monitoring and managing the JVM.

The API provides access to information such as:

Number of classes loaded and threads running
Virtual machine uptime, system properties, and JVM input arguments
Thread state, thread contention statistics, and stack trace of live threads
Memory consumption
Garbage collection statistics
Low memory detection
On-demand deadlock detection
Operating system information


What are MBeans?

MBeans are managed beans, Java objects that represent resources to be managed. An MBean has a management interface consisting of:

Named and typed attributes that can be read and written
Named and typed operations that can be invoked
Typed notifications that can be emitted by the MBean
For example, an MBean representing an application's configuration could have attributes representing the 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.

A standard MBean exposes the resource to be managed directly through its attributes and operations. Attributes are exposed through "getter" and "setter" methods. Operations are the other methods of the class that are available to managers. All these methods are defined statically in the MBean interface and are visible to a JMX agent through introspection. This is the most straightforward way of making a new resource manageable.

A dynamic MBean is an MBean that defines its management interface at runtime. For example, a configuration MBean could determine the names and types of the attributes it exposes by parsing an XML file.