Poonam's Weblog

« Previous day (May 20, 2007) | Main | Next day (May 22, 2007) »

http://blogs.sun.com/poonam/date/20070522 Tuesday May 22, 2007

Collector names for GarbageCollectorMXBean MXBean

While trying to use GarbageCollectorMXBean to obtain GC information about a running process, I had to look around to find out the correct name strings for various Garbage Collectors.

This is what I did to obtain an instance of GarbageCollectorMXBean:

  MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  GarbageCollectorMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server,
             GC_BEAN_NAME, GarbageCollectorMXBean.class);

where GC_BEAN_NAME is the ObjectName for uniquely identifying the MXBean for a garbage collector within an MBeanServer and it is of the form:
    java.lang:type=GarbageCollector,name=collector's name  

Now, what is the correct string for collector's name?

Here are the name strings for various collectors in VM:
    Copy 
    MarkSweepCompact
    ParNew
    ConcurrentMarkSweep
    PSScavenge
    PSMarkSweep   

You can run a simple java program with different collectors and using the below code snippet, can see the full object names of all the available GarbageCollectorMXBean MXBeans.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set names = mbs.queryNames(null, null);
System.out.println(names.toString().replace(", ",
    	    	    	System.getProperty("line.separator")));


Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.