X

Poonam Bajaj's Blog

Collector names for GarbageCollectorMXBean MXBean

Poonam Parhar
Consulting Member of Technical Staff
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")));

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.