KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > common > SysMonitor


1 /*
2  * Copyright (c) 2004 Your Corporation. All Rights Reserved.
3  */

4 package org.jfox.ioc.common;
5
6 import java.text.NumberFormat JavaDoc;
7
8 import org.jfox.ioc.ComponentContext;
9 import org.jfox.ioc.annotation.Managable;
10 import org.jfox.ioc.ext.ActiveComponent;
11 import org.jfox.ioc.ext.ManagableComponent;
12 import org.jfox.ioc.ext.SingletonComponent;
13
14 /**
15  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
16  */

17
18 public class SysMonitor implements ManagableComponent, ActiveComponent, SingletonComponent{
19     private static NumberFormat JavaDoc format = NumberFormat.getInstance();;
20
21     @Managable
22     public String JavaDoc getTotalMemory() {
23         long m = (long) (Runtime.getRuntime().totalMemory() / 1024);
24         return format.format(m) + " K";
25     }
26
27     @Managable
28     public String JavaDoc getFreeMemory() {
29         long m = (long) (Runtime.getRuntime().freeMemory() / 1024);
30         return format.format(m) + " K";
31     }
32
33     @Managable
34     public String JavaDoc getMaxMemory() {
35         long m = (long) (Runtime.getRuntime().maxMemory() / 1024);
36         return format.format(m) + " K";
37     }
38
39     @Managable
40     public int getThreadCount() {
41         return Thread.activeCount();
42     }
43
44     @Managable
45     public void gc() {
46         System.gc();
47     }
48
49     public void setComponentContext(ComponentContext ctx) {
50     }
51
52     public static void main(String JavaDoc[] args) {
53
54     }
55 }
56
57
Popular Tags