启动JVM时,Xms和Xmx参数是什么? [英] What are the Xms and Xmx parameters when starting JVMs?
问题描述
请解释在JVM中使用 Xms
和 Xmx
参数。它们的默认值是什么?
Please explain the use of Xms
and Xmx
parameters in JVMs. What are the default values for them?
推荐答案
标志 Xmx
指定Java虚拟机(JVM)的最大内存分配池,而 Xms
指定初始内存分配池。
The flag Xmx
specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms
specifies the initial memory allocation pool.
这意味着您的JVM将以 Xms
内存量启动,并且最多可以使用 Xmx
记忆量。例如,启动如下所示的JVM将启动256 MB的内存,并允许该进程使用最多2048 MB的内存:
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. For example, starting a JVM like below will start it with 256 MB of memory and will allow the process to use up to 2048 MB of memory:
java -Xms256m -Xmx2048m
内存标志也可以多种尺寸指定,例如千字节,兆字节等。
The memory flag can also be specified in multiple sizes, such as kilobytes, megabytes, and so on.
-Xmx1024k
-Xmx512m
-Xmx8g
Xms
标志没有默认值, Xmx
的默认值通常为256 MB。这些标志的常见用法是遇到 java.lang.OutOfMemoryError
。
The Xms
flag has no default value, and Xmx
typically has a default value of 256 MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError
.
使用这些设置时,请记住,这些设置适用于JVM的堆,并且JVM可以/将使用的内存多于分配给堆的大小。来自 Oracle的文档:
When using these settings, keep in mind that these settings are for the JVM's heap, and that the JVM can/will use more memory than just the size allocated to the heap. From Oracle's documentation:
请注意,JVM使用的内存多于堆。例如,Java方法,线程堆栈和本机句柄分配在与堆分开的内存中,以及JVM内部数据结构。
Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.
这篇关于启动JVM时,Xms和Xmx参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!