Take the 2-minute tour ×

Possible Duplicate:
Read Java JVM startup parameters (eg -Xmx)

I'm running an application on a Tomcat server, and I want to access the values of the -Xms -Xmx and -XX:MaxPermSize JVM argument values so that I can log them for help with debugging.

I've tried to find these arguments listed in System.properties, and using System.getEnv(), but they are not there. Is there another way to get them, or, alternately, is their lack of presence in System.properties and System.getEnv() an indication that these options have not been set?

share|improve this question

marked as duplicate by Tomasz Nurkiewicz, Jigar Joshi, cdeszaq, EJP, Andrew Barber Dec 20 '11 at 1:27


That's a helpful solution, although the Runtime.totalMemory() idea listed below is a good supplement to it, because it is helpful in the case where -Xms is not set, but you still want to see how much memory is there by default (as turned out to be the case with my issue). –  Spike Williams Dec 19 '11 at 17:40
Why do it programmatically? It's set in the Tomcat configuration. Just copy that on every startup. –  EJP Dec 19 '11 at 23:22
Because I do not control the servers, and do not have access to the Tomcat configuration without having to track down and bother system administrators. –  Spike Williams Dec 20 '11 at 16:23
add comment

2 Answers

You can get basic information from the Runtime class, including total, maximum and free memory; refer to Runtime JavaDoc for specifics.

If that isn't enough info, you can use the Management extensions to get a lot more information about current and peak memory usage in each of the memory pools. You can browse all of the available information for a running JVM using the MBeans tab on JConsole, which is included with the Oracle JDK. Specifically, look at the MBeans with object name java.lang:type=Memory, and java.lang:type=MemoryPool,name=*.

Once you've identified the MBeans with the information you need, you can access them programatically using the ManagementFactory class. This allows generic access to all MBeans (you can make your own), but has convenience methods for some of the MBeans provided by the platform, including:

share|improve this answer
add comment

What about Runtime.totalMemory() (of course if you have permissions, or security is disabled) ?

Another workaround is to search for the command line that has started the tomcat and parse it. In linux is easy, but in windows...

share|improve this answer
add comment
