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.

trincot
  • 317,000
  • 35
  • 244
  • 286
pamphlet
  • 2,054
  • 1
  • 17
  • 27

2 Answers2

6

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

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

Hope this helps.

Mike K.
  • 3,751
  • 28
  • 41
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".

alexvetter
  • 1,998
  • 2
  • 16
  • 42
  • 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! – pamphlet Sep 26 '11 at 19:00