programmatically set maximum Java heap size

Is there a way to set the maximum Java heap size programmatically and not as a vm argument?

Something like:

System.getProperties().put("<heap variable>", "1000m"); 
+6
java jvm heap-memory
source share
2 answers

Not with any JVM Hotspot. JVM heap parameters can only be specified on the command line and then committed to the JVM lifetime.

With the implementation of Java Hotspot, the only way to "resize" the application heap size is to restart it in the new JVM with various command line options.

(I vaguely remember that JVMs from some other providers allow you to change some heap parameters in a running JVM. Perhaps someone can clarify.)

+7
source share

You need to understand the difference between the JVM space and the environment in which it operates. This option you mentioned (and any other -X or -XX option) is configured for the environment provided by the environment that runs the JVM.

On a computer running Windows XP, Windows is the initiator of the JVM. Therefore, the JVM cannot change the parameter provided by the OS. This is logical.

@Stephen C, you may be right about some VM implementation that provides this function, but I'm not sure.

0
source share

All Articles