使用大量内存的 Java 应用程序。使用-Xmx?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1030256/
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
Java app that uses a lot of memory. Use -Xmx?
提问by Martin Redmond
I have a java app that uses about 15G on a machine with 16G. I don't know if I should set the max heap size.
我有一个 java 应用程序,在一台 16G 的机器上使用大约 15G。我不知道是否应该设置最大堆大小。
If set will the jvm eat all the ram up to the limit and then start garbage collecting and stop everything while it churns through 15G of heap objects?
如果设置,jvm 是否会吃掉所有内存到限制,然后开始垃圾收集并在它通过 15G 堆对象搅动时停止一切?
If not will the jvm hurt performance by not using all of the available ram on the machine.
如果没有,jvm 是否会因为不使用机器上的所有可用内存而损害性能。
My specific vm is: Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode).
我的特定虚拟机是:Java HotSpot(TM) 64 位服务器虚拟机(构建 1.6.0_03-b05,混合模式)。
Thanks
谢谢
采纳答案by Cogsy
-Xmx15G
will set the maximum heap size to 15 gig. Java will only allocate what it needs as it runs. If you don't set it, it will only use the default. For info on the default, see this post.
-Xmx15G
将最大堆大小设置为 15 gig。Java 只会在它运行时分配它需要的东西。如果你不设置它,它只会使用默认值。有关默认设置的信息,请参阅此帖子。
-Xms15G
sets the minimum heap to 15 gig. This forces java to allocate 15 gig of heap space before it starts executing, whether it needs it or not.
-Xms15G
将最小堆设置为 15 gig。这会强制 java 在开始执行之前分配 15 gig 的堆空间,无论它是否需要。
Usually you can set them both to appropriate values depending on how you're tuning the JVM.
通常,您可以将它们都设置为适当的值,具体取决于您如何调整 JVM。
回答by matt b
If you don't set a max heap size (with -Xmx
), isn't the default maximum only 64MB?
如果您没有设置最大堆大小(使用-Xmx
),那么默认的最大大小不是只有 64MB 吗?
So won't your application fail with OutOfMemoryError
s if you don't set it? I'm confused on this question. How can your application run without this switch?
那么OutOfMemoryError
如果你不设置它,你的应用程序会不会因为s 而失败?我对这个问题感到困惑。如果没有这个开关,你的应用程序如何运行?
回答by coobird
In Java 6, the default maximum heap size is determined by the amount of system memory present.
在 Java 6 中,默认的最大堆大小由存在的系统内存量决定。
According to the Garbage Collector Ergonomicspage, the maximum heap size is:
根据垃圾收集器人体工程学页面,最大堆大小为:
Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB.
物理内存的 1/4 或 1GB,以较小者为准。在 J2SE 5.0 之前,默认的最大堆大小是 64MB。
By using the -Xmx
switch can be used to change the maximum heap size. See the java
- the Java application launcherdocumentation for usage details.
通过使用该-Xmx
开关可用于更改最大堆大小。有关使用详细信息,请参阅java
- Java 应用程序启动器文档。