1 46 50 package org.mr.core.cmc; 51 52 import org.apache.commons.logging.Log; 53 import org.apache.commons.logging.LogFactory; 54 55 import javax.management.*; 56 57 62 public class GarbageCollectionJMX extends StandardMBean implements GarbageCollectionJMXMBean { 63 long free, memoryInVM, usedBefore, usedAfter; 64 public Log log; 65 66 public GarbageCollectionJMX()throws NotCompliantMBeanException { 67 super(GarbageCollectionJMXMBean.class); 68 log=LogFactory.getLog("GarbageCollectionJMX"); 69 } 70 71 75 public String collect() { 76 free = Runtime.getRuntime().freeMemory()/1000; 78 memoryInVM = Runtime.getRuntime().totalMemory()/1000; 79 usedBefore = memoryInVM - free; 80 81 Runtime.getRuntime().gc(); 82 83 free = Runtime.getRuntime().freeMemory()/1000; 84 memoryInVM = Runtime.getRuntime().totalMemory()/1000; 85 usedAfter = memoryInVM - free; 86 87 String result = "The VM used "+usedBefore+"KB memory befor GC , the VM used " 88 +usedAfter+" memory after GC , "+(usedBefore -usedAfter )+ " memory collected "; 89 return result; 90 } 91 92 protected String getDescription(MBeanInfo i_mBeanInfo) { 93 return "Does Garbage Collection and returnds the results of it."; 94 } 95 96 protected String getDescription(MBeanOperationInfo i_mBeanOperationInfo) { 97 return "Does Garbage Collection"; 98 } 99 } 100 | Popular Tags |