5

I have reviewed the answer to how to get the min and max heap size settings of a JVM from within a Java program which was helpful, but the accepted answer doesn't appear to answer half of the question. In essence, I want to report the -Xms and -Xmx settings that were used when the JVM was launched.

2 Answers 2

6

These are the mappings between values you're looking for:

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

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

The total memory is the same as the -ms on startup, but might be higher after it start running.
3

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

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

You have to look for the arguments which start with "-Xm(s|x)". The problem is that the value could be something like "256M".

1 Comment

Perfect for my needs. We just want to log the JVM settings at start-up to provide some context when reviewing logs associated with problem reports. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.