KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > drda > memCheck


1 /*
2
3    Derby - Class org.apache.derby.impl.drda.memCheck
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.drda;
23
24 import java.util.Date JavaDoc;
25
26 public class memCheck extends Thread JavaDoc {
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 JavaDoc ie) {
42             System.out.println("memcheck interrupted");
43             stopNow = true;
44         }
45     }
46 }
47
48     public static String JavaDoc getMemInfo() {
49     Runtime JavaDoc 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 JavaDoc rt = Runtime.getRuntime();
61         return rt.totalMemory();
62     }
63
64     public static long freeMemory() {
65         
66         Runtime JavaDoc rt = Runtime.getRuntime();
67         rt.gc();
68         return rt.freeMemory();
69     }
70
71     public static void showmem() {
72     Date JavaDoc d = null;
73     d = new Date JavaDoc();
74     System.out.println(getMemInfo() + " " + d.toString());
75
76 }
77
78 public static void main (String JavaDoc argv[]) {
79     System.out.println("memCheck starting");
80     memCheck mc = new memCheck();
81     mc.run();
82 }
83 }
84
Popular Tags