开发者

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

开发者 https://www.devze.com 2023-04-09 08:37 出处:网络
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 correc开发者_高级运维

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 correc开发者_高级运维tly. Is there a way to check the configured Xmx value when the application is running?


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.


Cheap and dirty (not sure on reliability):

Runtime.getRuntime().maxMemory();

Have also used the following with success:

    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    memoryBean.getHeapMemoryUsage().getMax();


jps is a good solution, just run

jps # shows pids
jps -v <pid> # shows params

remember to run it as the user that launched the process though, or it will not work properly.


Doron Gold gave the correct answer for Java 8 and below. For Java 9 and above you can get the same info by using

jhsdb jmap --heap --pid <pid>


I'm a big fan of kill -3 < pid > , which will give you details on the current memory and garbage collections along with stacks for all threads.


The following worked for me for JVM version 11.0.16 (I had installed OpenJDK 11)

sudo jhsdb jinfo --flags --pid <pid>

It may work for you without using "sudo".

I had to do this after sudo jhsdb jmap --heap --pid <pid> was giving me the following error message: Exception in thread "main" sun.jvm.hotspot.types.WrongTypeException: No suitable match for type of address

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号