| sitelink1 | |
|---|---|
| sitelink2 | |
| sitelink3 | http://1 | 
| sitelink4 | http://ko | 
| sitelink5 | http://cafe.naver.com/itwillmulticampus....icleid=312 | 
| sitelink6 | http://sitelink1 | 
메모리 사용량 확인
Runtime의 maxMemory, totalMemory, freeMemory 메소드를 이용하면 현재 애플리케이션이 사용하고 있는 메모리 상태를 확인 할 수 있습니다.
아래의 예제를 확인 하세요~
import java.text.DecimalFormat;   
public class MonitorMemory {   
        static Runtime r = Runtime.getRuntime();   
        public static void main(String[] args) {   
                showMemory();   
        }   
        public static void showMemory() {   
                DecimalFormat format = new DecimalFormat("###,###,###.##");   
                //JVM이 현재 시스템에 요구 가능한 최대 메모리량, 이 값을 넘으면 OutOfMemory 오류가 발생 합니다.                   
                long max = r.maxMemory();   
                //JVM이 현재 시스템에 얻어 쓴 메모리의 총량   
                long total = r.totalMemory();   
                //JVM이 현재 시스템에 청구하여 사용중인 최대 메모리(total)중에서 사용 가능한 메모리   
                long free = r.freeMemory();   
                System.out.println("Max:" + format.format(max) + ", Total:" + format.format(total) + ", Free:"+format.format(free));           
        }   
}
실행시 아래처럼 JVM의 메모리 값을 서로 다른 양으로 요구 할 수 있습니다.
물론 이전의 강좌에도 있었지만 실행 시 OutOfMemory 오류 발생시에도 적절히 JVM의 메모리 요구량을 조절 하시면 됩니다.
[결과]
D:Tomcat-ProjectJavaApp>java -Xmx128m  MonitorMemory
Max:133,234,688, Total:2,031,616, Free:1,590,304
D:Tomcat-ProjectJavaApp>java -Xmx64m  MonitorMemory
Max:66,650,112, Total:2,031,616, Free:1,590,304
D:Tomcat-ProjectJavaApp>java -Xmx64m -Xms32m  MonitorMemory
Max:66,650,112, Total:33,357,824, Free:32,893,104 
 
							
