1 21 22 package org.apache.derby.impl.drda; 23 24 import java.util.Date ; 25 26 public class memCheck extends Thread { 27 int delay = 200000; 28 boolean stopNow = false; 29 30 public memCheck () {} 31 32 public memCheck (int num) { 33 delay = num; 34 } 35 36 public void run () { 37 while (stopNow == false) { 38 try { 39 showmem(); 40 sleep(delay); 41 } catch (java.lang.InterruptedException ie) { 42 System.out.println("memcheck interrupted"); 43 stopNow = true; 44 } 45 } 46 } 47 48 public static String getMemInfo() { 49 Runtime rt = null; 50 rt = Runtime.getRuntime(); 51 rt.gc(); 52 return "total memory: " 53 + rt.totalMemory() 54 + " free: " 55 + rt.freeMemory(); 56 57 } 58 59 public static long totalMemory() { 60 Runtime rt = Runtime.getRuntime(); 61 return rt.totalMemory(); 62 } 63 64 public static long freeMemory() { 65 66 Runtime rt = Runtime.getRuntime(); 67 rt.gc(); 68 return rt.freeMemory(); 69 } 70 71 public static void showmem() { 72 Date d = null; 73 d = new Date (); 74 System.out.println(getMemInfo() + " " + d.toString()); 75 76 } 77 78 public static void main (String argv[]) { 79 System.out.println("memCheck starting"); 80 memCheck mc = new memCheck(); 81 mc.run(); 82 } 83 } 84 | Popular Tags |