자바 jvm 프로그램 실행 메모리 테스트

1887 단어 Java
free: 이 방법 은 미래 분배 대상 의 현재 사용 가능 한 메모리 와 비슷 한 총량 을 되 돌려 줍 니 다.
total: 자바 가상 머 신 은 현재 조종 시스템 에서 파 낸 메모리 크기 입 니 다.
max: 자바 가상 머 신 (이 프로 세 스) 은 조종 시스템 에서 파 낸 가장 큰 메모 리 를 구성 할 수 있 습 니 다.
package Test;

public class Test {

    public static void main(String[] args) {	
    	System.out.println("free:" + Runtime.getRuntime().freeMemory() / 1024 / 1024);  
        System.out.println("total:" + Runtime.getRuntime().totalMemory() / 1024 / 1024);  
        System.out.println("max:" + Runtime.getRuntime().maxMemory() / 1024 / 1024);  
        System.out.println("=============");  
        try {  
            Thread.sleep(3000);  
        } catch (Exception ee) {  
            ee.printStackTrace();  
        }  
        String[] aaa = new String[2000000];  
    	System.out.println("free:" + Runtime.getRuntime().freeMemory() / 1024 / 1024);  
        System.out.println("total:" + Runtime.getRuntime().totalMemory() / 1024 / 1024);  
        System.out.println("max:" + Runtime.getRuntime().maxMemory() / 1024 / 1024);  
        System.out.println("=============");  
        try {  
            Thread.sleep(3000);  
        } catch (Exception ee) {  
            ee.printStackTrace();  
        }  
        for (int i = 0; i < 2000000; i++) {  
            aaa[i] = new String("aaa");  
        }  
    	System.out.println("free:" + Runtime.getRuntime().freeMemory() / 1024 / 1024);  
        System.out.println("total:" + Runtime.getRuntime().totalMemory() / 1024 / 1024);  
        System.out.println("max:" + Runtime.getRuntime().maxMemory() / 1024 / 1024);  
        System.out.println("=============");  
        try {  
            Thread.sleep(3000);  
        } catch (Exception ee) {  
            ee.printStackTrace();  
        } 
    }
}

좋은 웹페이지 즐겨찾기