Is there a way to set the max java heap size programatically instead of as a vm argument?
Something like:
System.getProperties().put("<heap variable>", "1000m");
Is there a way to set the max java heap size programatically 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.