How to get the min and max heap size settings of a VM from within a Java program?
views:
272answers:
3
+4
A:
max heap size:
Runtime.getRuntime().maxMemory();
Some other calculations which you may find interesting:
Runtime runtime = Runtime.getRuntime();
long maxMemory = runtime.maxMemory();
long allocatedMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();
long totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
long usedMemory = maxMemory - totalFreeMemory;
cherouvim
2010-02-12 18:07:20
I have set my max heap size as 512m.Runtime.getRuntime().maxMemory() returns 532742144 which is 508.0625
java_geek
2010-02-12 18:14:00
@sai praveen: yep, and if you set it to 1024m it will return something that approximates 1024m.
cherouvim
2010-02-12 20:50:41
+3
A:
You just need to use the Runtime object with Runtime.getRuntime() and then use methods like totalMemory() freeMemory()
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#freeMemory()
metismo
2010-02-12 18:08:30
A:
maybe that could help you ?
http://download.oracle.com/docs/cd/E11035_01/wls100/perform/JVMTuning.html#wp1109778 http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp http://blog.paulgu.com/2008/07/19/6-common-errors-in-setting-java-heap-size/
marc-andre menard
2010-02-12 18:09:03