Java 8 中默认的最大堆大小 (-Xmx) 是多少? [英] What is the default max heap size (-Xmx) in Java 8?
问题描述
在 oracle 文档中,我发现:
-Xmxsize 以字节为单位指定内存分配池的最大大小(以字节为单位)...默认值是在运行时根据系统配置选择的.
-Xmxsize Specifies the maximum size (in bytes) of the memory allocation pool in bytes ... The default value is chosen at runtime based on system configuration.
系统配置是什么意思?
推荐答案
它因实现和版本而异,但通常取决于所使用的 VM(例如客户端或服务器,参见 -client
和 -server
参数)和您的系统内存.
It varies on implementation and version, but usually it depends on the VM used (e.g. client or server, see -client
and -server
parameters) and on your system memory.
通常client
的默认值是物理内存的 1/4 或 1GB(以较小者为准).
Often for client
the default value is 1/4th of your physical memory or 1GB (whichever is smaller).
Java 配置选项(命令行参数)也可以外包"给环境变量,包括 -Xmx
,它可以更改默认值(意味着指定新的默认值).特别是 JAVA_TOOL_OPTIONS
环境变量由所有 Java 工具检查并在存在时使用(更多详细信息 这里 和 此处).
Also Java configuration options (command line parameters) can be "outsourced" to environment variables including the -Xmx
, which can change the default (meaning specify a new default). Specifically the JAVA_TOOL_OPTIONS
environment variable is checked by all Java tools and used if exists (more details here and here).
您可以运行以下命令查看默认值:
You can run the following command to see default values:
java -XX:+PrintFlagsFinal -version
它给你一个loooong列表,-Xmx
在MaxHeapSize
中,-Xms
在InitialHeapSize
中.过滤您的输出(例如 Linux 上的 |grep
)或将其保存在一个文件中,以便您可以在其中进行搜索.
It gives you a loooong list, -Xmx
is in MaxHeapSize
, -Xms
is in InitialHeapSize
. Filter your output (e.g. |grep
on linux) or save it in a file so you can search in it.
这篇关于Java 8 中默认的最大堆大小 (-Xmx) 是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!