Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically setting max java heap size

Is there a way to set the max java heap size programmatically instead of as a vm argument?

Something like:

System.getProperties().put("<heap variable>", "1000m");
like image 577
MBU Avatar asked Jan 25 '11 02:01

MBU


People also ask

How do I set maximum heap size?

Under the Java tab, select JVM Options. Edit the -Xmx256m option. This option sets the JVM heap size. Set the -Xmx256m option to a higher value, such as Xmx1024m.

Which JVM parameter sets maximum heap size?

-Xmx to specify the maximum heap size.

How do I fix invalid max heap size?

If you look carefully you will space between -Xmx and 1800M, which is causing "Could not create the Java virtual machine: Invalid maximum heap size -Xmx". syntactically there should not be any space between -Xmx and heap size. Just remove the space between -Xmx and 1400M and it will work.


1 Answers

Not with any Hotspot JVM. The JVM heap parameters can only be specified on the command line, and are then fixed for the lifetime of the JVM.

With Hotspot Java implementations, the only way to "change" the heap size of an application is to relaunch it in a new JVM with different command line parameters.

(I vaguely recall that JVMs from some other vendors do allow some heap parameters to be changed in a running JVM. Perhaps someone can clarify.)

like image 156
Stephen C Avatar answered Oct 02 '22 10:10

Stephen C