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