KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > util > MemoryMonitor


1 /*
2  * Created on Dec 4, 2004
3  */

4 package com.openedit.util;
5
6 import java.math.BigDecimal JavaDoc;
7
8 /**
9  * @author Matthew Avery, mavery@einnovation.com
10  */

11 public class MemoryMonitor
12 {
13     public static final BigDecimal JavaDoc MEG = new BigDecimal JavaDoc( 1024 * 1024 );
14     
15     public String JavaDoc getTotalMemory()
16     {
17         return print( Runtime.getRuntime().totalMemory() );
18     }
19     private String JavaDoc print( long inTotal )
20     {
21         BigDecimal JavaDoc total = new BigDecimal JavaDoc( inTotal );
22         return total.divide( MEG, 2, BigDecimal.ROUND_HALF_UP ) + " MB";
23     }
24     public String JavaDoc getFreeMemory()
25     {
26         return print( Runtime.getRuntime().freeMemory() );
27     }
28     public String JavaDoc getMaxMemory()
29     {
30         return print( Runtime.getRuntime().maxMemory() );
31     }
32
33
34 }
35
Popular Tags