Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the min and max heap size settings of a JVM from within a Java program

How to get the min and max heap size settings of a VM from within a Java program?

like image 840
java_geek Avatar asked Feb 12 '10 18:02

java_geek


4 Answers

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;
like image 167
cherouvim Avatar answered Nov 17 '22 21:11

cherouvim


You just need to use the Runtime object with Runtime.getRuntime() and then use methods like totalMemory() and freeMemory().

like image 43
metismo Avatar answered Nov 17 '22 23:11

metismo


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/

like image 1
menardmam Avatar answered Nov 17 '22 21:11

menardmam


ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
like image 1
instantsetsuna Avatar answered Nov 17 '22 22:11

instantsetsuna