找出给定 java 进程的 -Xms 和 -Xmx 变量值的命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27959837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:42:57  来源:igfitidea点击:

Command to find out -Xms and -Xmx variable values for a given java process?

javajvmjava-opts

提问by Adon Smith

I have a java program, which i ran and figured out its process id with jps.

我有一个java程序,我运行它并用jps计算出它的进程ID。

How can i see what is the value of -Xms and -Xmx variable for this java process ?

我如何才能看到这个 java 进程的 -Xms 和 -Xmx 变量的值是多少?

回答by apangin

Try

尝试

jcmd <PID> VM.command_line
jcmd <PID> VM.flags

回答by SQL.injection

you can use jps and do it from the command line:

您可以使用 jps 并从命令行执行此操作:

jps # shows pids
jps -v <pid> # shows params
jps -v <localhost:pid> # the host must be indicated

if this is not enough you can do it programmatically inside the program to check the maximum amount of memory that the Java virtual machine will attempt to use:

如果这还不够,您可以在程序内部以编程方式执行此操作,以检查Java 虚拟机将尝试使用最大内存量

Runtime.getRuntime().maxMemory()

and you can also use use the class MemoryUsageto get the initial, used and max ammount that can be used for memory management.

您还可以使用MemoryUsage类来获取可用于内存管理的初始、已用和最大数量。

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

回答by Hunter Zhao

I think jmapcommand will give you everything you want.
usage: jmap -heap {pid}

我认为jmap命令会给你你想要的一切。
用法:jmap -heap {pid}

root@BobServerStation:/usr/local $ jmap -heap 3280
Attaching to process ID 3280, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.65-b04

using thread-local object allocation.
Parallel GC with 8 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 0
   MaxHeapFreeRatio = 100
   MaxHeapSize      = 4116709376 (3926.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 85983232 (82.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 65011712 (62.0MB)
   used     = 42273152 (40.3148193359375MB)
   free     = 22738560 (21.6851806640625MB)
   65.0239021547379% used
From Space:
   capacity = 10485760 (10.0MB)
   used     = 10479760 (9.994277954101562MB)
   free     = 6000 (0.0057220458984375MB)
   99.94277954101562% used
To Space:
   capacity = 10485760 (10.0MB)
   used     = 0 (0.0MB)
   free     = 10485760 (10.0MB)
   0.0% used
PS Old Generation
   capacity = 171442176 (163.5MB)
   used     = 376368 (0.3589324951171875MB)
   free     = 171065808 (163.1410675048828MB)
   0.21953057805332568% used
PS Perm Generation
   capacity = 22020096 (21.0MB)
   used     = 15401488 (14.688003540039062MB)
   free     = 6618608 (6.3119964599609375MB)
   69.94287400018601% used

8464 interned Strings occupying 699456 bytes.