1 30 31 package rcm.util; 32 33 public abstract class Mem { 34 35 public static long free () { 36 return Runtime.getRuntime ().freeMemory (); 37 } 38 39 public static long used () { 40 Runtime r = Runtime.getRuntime (); 41 return r.totalMemory() - r.freeMemory (); 42 } 43 44 public static long total () { 45 return Runtime.getRuntime ().totalMemory (); 46 } 47 48 public static String getReport () { 49 return "Memory: used " + (used()/1000) + "KB, free " 50 + (free()/1000) + "KB, total " + (total()/1000) + "KB"; 51 } 52 53 public static void gc () { 54 Runtime r = Runtime.getRuntime (); 55 r.runFinalization (); 56 r.gc (); 57 } 58 59 public static void dumpThreadInfo () { 60 ThreadGroup g = Thread.currentThread().getThreadGroup (); 61 Thread [] t = new Thread [g.activeCount ()]; 62 g.enumerate (t); 63 System.err.println ("Active threads in " + g); 64 for (int i=0; i<t.length; ++i) 65 System.err.println (t[i]); 66 } 67 68 } 69 | Popular Tags |