简体   繁体   中英

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");

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.)

You need to understand the difference between JVM space and the environment it runs in. The parameter that you have mentioned (and any other -X or -XX parameter) are environment set up provided by the environment that runs the JVM.

In an Windows XP machine, Windows OS is THE initiator of the JVM. Hence JVM should not be able to change a parameter that the OS provided. It's logical.

@Stephen C, may be you are right about some VM implementation that provide this feature, but I am not sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM