How to determine the size of the minimum JVM heap from a java application?

I looked at the answer on how to get the minimum and maximum JVM heap size settings from a Java program , which was useful, but the accepted answer seems to have answered half the question. In essence, I want to report the -Xms and -Xmx options that were used when starting the JVM.

+5
source share
2 answers

If you want to get real JVM arguments, this should help you. You can get all the JVM arguments using MXBean:

RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = RuntimemxBean.getInputArguments();

You need to look for arguments starting with "-Xm (s | x)". The problem is that the value may be something like “256M”.

+3

, :

-Xmx=Runtime.getRuntime().maxMemory()
-Xms=Runtime.getRuntime().totalMemory()

, .

+6

All Articles