As we all know, the java -Xmx option is used to set the maximum heap space available to a Java program. But is there a way for a Java program to read the value that has been set? Something like System.getMaximumHeapSpace() (which does not exist).
As we all know, the java -Xmx option is used to set the maximum
Share
There is a
Runtime.maxMemory, which the documentation says will return the maximum amount of memory the Java Virtual Machine will attempt to use, but it is not specific whether it is the maximum heap memory set when launching the JVM.Just as a test, I wrote the following program:
The results of the execution was the following:
This is using Java SE 6 version 1.6.0_12 on Windows.
Although the values are close to 64 MB (67,108,864 bytes) and 128 MB (134,217,728 bytes), they aren’t exactly so.