Monitoring and Manageability
Monitoring and Manageability is a key component of RAS (Reliability, Availability, Serviceability) in the Java platform.
The JVM Monitoring & Management API (JSR-174) specifies a comprehensive set of JVM internals that can be monitored from a running JVM. This information is accessed through JMX (JSR-003) MBeans and can also be accessed remotely using the JMX remote interface (JSR-160) and through industry standard SNMP tools.
One of the most useful features is a low memory detector. JMX MBeans can notify registered listeners when the threshold is crossed, see javax.management and java.lang.management for details.
For an idea of how easy the new API is to use, the following reports the detailed usage of the memory heaps in the Hotspot JVM.
import java.lang.management.*;
import java.util.*;
import javax.management.*;
public class MemTest {
public static void main(String args[]) {
List pools =ManagementFactory.getMemoryPoolMBeans();
for(ListIterator i = pools.listIterator(); i.hasNext();) {
MemoryPoolMBean p = (MemoryPoolMBean) i.next();
System.out.println("Memory type="+p.getType()+" Memory usage="+p.getUsage());
}
}
}
|