01: /*
02:
03: Derby - Class org.apache.derby.impl.drda.memCheck
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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;
25:
26: public class memCheck extends Thread {
27: int delay = 200000;
28: boolean stopNow = false;
29:
30: public memCheck() {
31: }
32:
33: public memCheck(int num) {
34: delay = num;
35: }
36:
37: public void run() {
38: while (stopNow == false) {
39: try {
40: showmem();
41: sleep(delay);
42: } catch (java.lang.InterruptedException ie) {
43: System.out.println("memcheck interrupted");
44: stopNow = true;
45: }
46: }
47: }
48:
49: public static String getMemInfo() {
50: Runtime rt = null;
51: rt = Runtime.getRuntime();
52: rt.gc();
53: return "total memory: " + rt.totalMemory() + " free: "
54: + rt.freeMemory();
55:
56: }
57:
58: public static long totalMemory() {
59: Runtime rt = Runtime.getRuntime();
60: return rt.totalMemory();
61: }
62:
63: public static long freeMemory() {
64:
65: Runtime rt = Runtime.getRuntime();
66: rt.gc();
67: return rt.freeMemory();
68: }
69:
70: public static void showmem() {
71: Date d = null;
72: d = new Date();
73: System.out.println(getMemInfo() + " " + d.toString());
74:
75: }
76:
77: public static void main(String argv[]) {
78: System.out.println("memCheck starting");
79: memCheck mc = new memCheck();
80: mc.run();
81: }
82: }
|