启动JVM时,-Xms和-Xmx参数是什么? [英] What are the -Xms and -Xmx parameters when starting JVM?
问题描述
请说明JVM中Xms
和Xmx
参数的用法.它们的默认值是什么?
标志Xmx
指定Java虚拟机(JVM)的最大内存分配池,而Xms
指定初始内存分配池. >
这意味着您的JVM将以Xms
的内存量启动,并且最多可以使用Xmx
的内存量.例如,启动如下所示的JVM将以256MB的内存启动它,并允许该进程使用多达2048MB的内存:
java -Xms256m -Xmx2048m
还可以使用不同的大小来指定内存标志,例如千字节,兆字节等.
-Xmx1024k
-Xmx512m
-Xmx8g
Xms
标志没有默认值,Xmx
通常具有256MB的默认值.这些标志的常见用法是遇到java.lang.OutOfMemoryError
.
使用这些设置时,请记住,这些设置是针对JVM的 heap 的,并且JVM可以/将使用更多的内存,而不仅仅是分配给堆的大小.来自 Oracle的文档:
请注意,JVM使用的内存不仅仅是堆.例如,Java方法,线程堆栈和本机句柄与堆以及JVM内部数据结构分开分配在内存中.
Please explain the use of Xms
and Xmx
parameters in JVMs. What are the default values for them?
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. 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 different sizes, such as kilobytes, megabytes, and so on.
-Xmx1024k
-Xmx512m
-Xmx8g
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
.
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:
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屋!