Reputation: 818
How to set java heap size and check it manually?
Upvotes: 0
Views: 7057
Reputation: 6124
java -X
in the command line reveals a list of parameters that you can use to fine-tune your JVM. Most notably, when it comes to heap -Xms
and -Xmx
which allow you to set the initial heap size and the maximum heap size.
You can check this at any point with Runtime.getRuntime().freeMemory()
-- however it's worth noticing that if you started JVM with say 100MB (heap start) and 1GB heap max your free memory could be initially 100MB (if there's nothing on heap) and then grow as the heap expands up to 1Gb. If however you set the initial size and the max size to be the same then freeMemory() will always reflect the exact free memory left in the heap since the heap will never get expanded.
Upvotes: 0
Reputation: 240956
just add following switch
-Xms -Xmx
-Xmx
for maximum heap size, and -Xms
for initial heap size.
To get the heap size
Runtime.getRuntime().totalMemory();
Upvotes: 0
Reputation: 313
See this http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp if you want to watch how much memory is consuming and more by your program, use jvisualvm.exe (this will be available under %JAVA_HOME%/bin folder)
Upvotes: 3
Reputation: 533820
You can set the minimum and maximum heap sizes with the -ms
and -mx
options. You can also use the older -Xms
and -Xmx
options.
What do you mean by checking it manually? You can view the heap sizes using jconsole
.
Upvotes: 1