develog

memory 본문

Dev/Java

memory

냐옴 2014. 9. 10. 14:42

public class TestMain {


public static void main(String[] args) {

System.out.println("START");

System.out.println("----------------------------------------------");

/*


totalMemory

Returns the total amount of memory in the Java virtual machine.

maxMemory

Returns the maximum amount of memory that the Java virtual machine will attempt to use.

freeMemory

Returns the amount of free memory in the Java Virtual Machine.


*/

Runtime r = Runtime.getRuntime();

printSize("totalMemory", r.totalMemory());

printSize("maxMemory", r.maxMemory());

printSize("freeMemory", r.freeMemory());

System.out.println("----------------------------------------------");

System.out.println("END");

}

private static void printSize(String memType, long bytes) {

String TAB = "\t";

System.out.print(memType);

System.out.print(TAB + bytes);

System.out.print(TAB + getKB(bytes));

System.out.print(TAB + getMB(bytes));

System.out.println();

}

private static String getKB(long bytes) {

String r = (bytes / 1024) + " KB";

return r;

}

private static String getMB(long bytes) {

String r = (bytes / 1024 / 1024) + " MB";

return r;

}

}


// output

START

----------------------------------------------

totalMemory 10682368 10432 KB 10 MB

maxMemory 18677760 18240 KB 17 MB

freeMemory 10406024 10162 KB 9 MB

----------------------------------------------

END


'Dev > Java' 카테고리의 다른 글

[Java] http 인증 접속  (0) 2014.09.18
[Java] System.getProperties(), System.getProperty()  (0) 2014.09.15
eclipse.ini  (0) 2014.09.10
[Java] 익명 PL/SQL 블럭 실행  (0) 2014.08.29
[Spring] dbcp 설정  (0) 2014.08.08
Comments