4

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?

3
  • 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). Commented Dec 19, 2011 at 17:40
  • Why do it programmatically? It's set in the Tomcat configuration. Just copy that on every startup. Commented Dec 19, 2011 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. Commented Dec 20, 2011 at 16:23

2 Answers 2

4

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...

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

1 Comment

This is for Xms. For Xmx Runtime.getRuntime().maxMemory() can be used.
4

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:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.