Read Java JVM startup options (e.g. -Xmx)

I am trying to figure out if there is a way to determine the properties of the JVM startup from a running java process. In particular, I'm trying to figure out where options like -Xmx (maximum heap size) and -XX: MaxPermSize are stored. I am running Sun 1.6 jvm.

If you're wondering why I want to do this, I have several JVM web servers that may or may not be configured correctly, and I want to add this to the startup code check. It is much easier for me to check a piece of java code that is deployed everywhere than manually find and verify all jvm startup files. Right now, jvm configuration files, for better or worse, are not part of our build process or are checked in the source control.

+45
java jvm configuration jvm-hotspot
Oct 05 '09 at 3:59
source share
2 answers

Try:

import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.List; public void runtimeParameters() { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); List<String> aList = bean.getInputArguments(); for (int i = 0; i < aList.size(); i++) { System.out.println( aList.get( i ) ); } } 

This should show all JVM parameters.

Note. We do not have JVM parameters in VCS, but in the database read by our own launchers in the products. Thus, we can remotely modify these values ​​without having to redeploy the parameters of the JVM parameter file.




You will find a good appreciation of the various JVM tools for use in this article (from "Dustin Software Cogitations and Speculations" ), including the Java Application Launcher links to:

This method uses the MXBeans platform available with J2SE 5 (custom MXBeans support was added in Java SE 6 ).

Two useful sources of JVM parameter information available when using the Sun JVM are:

Both of these resources list and describe some / all of the optional double X arguments not recommended for casual developers ( -XX ) that are available.

+52
Oct 05 '09 at 4:20
source share
β€” -

With Java 7 or later, it's as easy as

java -XshowSettings:all

+9
Jan 17 '13 at 17:54
source share



All Articles