Java – how to detect the actual value of – Xmx param? Runtime. getRuntime(). Maxmemory() is inaccurate
In my case, this value is usually different from the - Xmx. I specified
For - xmx810m, it returns 821035008, or 783mb Depending on various (not really reliable) sources, it should completely return the value specified by the - Xmx parameter
I'm looking for:
>Some reliable ways to find the exact value of - Xmx > some reliable sources will prove that maxmemory() is inaccurate
Solution
According to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4391499 (it may have changed in a newer version of the JVM since 2001):
The interpretation of the - Xmx flag depends on the VM. Some virtual machines, including hotspot, enforce the lower limit of the valid value of this option“
Therefore, as stated in the previous answer, maxmemory is accurate and the Xmx flag is just a suggestion
The above link is found through the answer to so's earlier similar question
If you want to find the user specified Xmx value, if you use the sun (ahem, Oracle) JVM /, you can roughly do the following:
String commandLineInput = System.getProperty("sun.java.command"); Pattern pattern = Pattern.compile("-Xmx(\\w*)"); Matcher matcher = pattern.matcher(commandLineInput); while(matcher.find()) { System.out.println(matcher.group(1)); }