Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the configured Xmx value for a running java application

Tags:

I'm creating an NSIS script, where the Xmx value for the java application being installed can be set during the installation process. I'm not sure if this parameter is being set correctly. Is there a way to check the configured Xmx value when the application is running?

like image 536
Philippe Avatar asked Sep 30 '11 14:09

Philippe


People also ask

How do I check my Java heap?

You can verify that the JVM is using the increased Java heap space: Open a terminal window. Review the command output. The argument beginning with "-Xmx" will give you the value of the current Java heap space.

What is Xms and XMX parameter in Java?

The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool. This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.

How do you set the max and min value of JVM memory?

use the arguments -Xms<memory> -Xmx<memory> . Use M or G after the numbers for indicating Megs and Gigs of bytes respectively. -Xms indicates the minimum and -Xmx the maximum. you may want to look at MaxPermSize as well.

Why is my JVM using more memory than XMX?

What you have specified via the -Xmx switches is limiting the memory consumed by your application heap. But besides the memory consumed by your application, the JVM itself also needs some elbow room. The need for it derives from several different reasons: Garbage collection.


2 Answers

In my case, jmap is the best solution I could find:

jmap -heap <pid> 

The above command shows full heap configuration + current usage.

The jmap command is included inside the jdk in the bin directory.

like image 120
Doron Gold Avatar answered Nov 27 '22 15:11

Doron Gold


Cheap and dirty (not sure on reliability):

Runtime.getRuntime().maxMemory();

Have also used the following with success:

    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    memoryBean.getHeapMemoryUsage().getMax();
like image 34
Nate Avatar answered Nov 27 '22 14:11

Nate