增加 Java 堆大小
我正在使用 8 GB RAM 的 Windows 2003 服务器(64 位)。如何增加堆内存最大值?我使用 -Xmx1500m
标志将堆大小增加到 1500 Mb。我可以将堆内存增加到物理内存(6 GB 堆)的 75% 吗?
I am working on a Windows 2003 server (64-bit) with 8 GB RAM. How can I increase the heap memory maximum? I am using the -Xmx1500m
flag to increase the heap size to 1500 Mb. Can I increase the heap memory to 75% of physical memory (6 GB Heap)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
在
32
位系统上,您可以增加到2GB
。如果您使用的是 64 位系统,则可以更高。如果您选择错误,无需担心,如果您在 32 位系统上请求 5g,java 会抱怨值无效并退出。正如其他人发布的那样,使用 cmd 行标志 - 例如,
您可以通过键入 java -X 获得完整列表(或几乎完整列表)。
You can increase to
2GB
on a32
bit system. If you're on a 64 bit system you can go higher. No need to worry if you've chosen incorrectly, if you ask for 5g on a 32 bit system java will complain about an invalid value and quit.As others have posted, use the cmd-line flags - e.g.
You can get a full list (or a nearly full list, anyway) by typing java -X.
可以使用以下命令行选项增加 JVM 分配的堆大小:
在以下示例中,最小堆大小设置为 16mb,最大堆大小设置为 64mb:
It is possible to increase heap size allocated by the JVM by using these command line options:
In the following example, minimum heap size is set to 16mb, and the maximum to 64mb:
在 32 位 JVM 上,理论上可以设置的最大堆大小是 4GB。要使用更大的堆大小,您需要使用 64 位 JVM。请尝试以下操作:
-d64 标志很重要,因为它告诉 JVM 以 64 位模式运行。
On a 32-bit JVM, the largest heap size you can theoretically set is 4gb. To use a larger heap size, you need to use a 64-bit JVM. Try the following:
The -d64 flag is important as this tells the JVM to run in 64-bit mode.
您可以通过传递 JVM 参数 -Xms 和 -Xmx 来增加堆大小,如下所示:
对于 Jar 文件:
对于 Java 文件:
上述参数增加了 InitialHeapSize ( -Xms) 至 4GB (4096 MB),MaxHeapSize(-Xmx) 至 6GB (6144 MB)。
但是,年轻代堆大小将保持不变,额外的堆大小将添加到老代堆大小中。要均衡年轻代堆和老一代堆的大小,请使用-XX:NewRatio=1 -XX:-UseAdaptiveSizePolicy参数。
-XX:NewRatio = Old Gen Heap Size : Young Gen HeapSize(您可以使用此比率来获得所需的比率)。
You can increase the Heap Size by passing JVM parameters -Xms and -Xmx like below:
For Jar Files:
For Java Files:
The above parameters increase the InitialHeapSize (-Xms) to 4GB (4096 MB) and MaxHeapSize(-Xmx) to 6GB (6144 MB).
But, the Young Generation Heap Size will remain same and the additional HeapSize will be added to the Old Generation Heap Size. To equalize the size of Young Gen Heap and Old Gen Heap, use -XX:NewRatio=1 -XX:-UseAdaptiveSizePolicy params.
-XX:NewRatio = Old Gen Heap Size : Young Gen HeapSize (You can play with this ratio to get your desired ratio).
可以直接在eclipse中增加JVM分配的堆大小
在 eclipse IDE 中转到
Run---->Run Configurations---->Arguments
输入 -Xmx1g(用于设置最大大小,如 Xmx256m 或 Xmx1g...... m-->mb g- --> GB)
It is possible to increase heap size allocated by the JVM in eclipse directly
In eclipse IDE goto
Run---->Run Configurations---->Arguments
Enter -Xmx1g(It is used to set the max size like Xmx256m or Xmx1g...... m-->mb g--->gb)
java -d64 -Xms512m -Xmx4g HelloWorld
其中,
-d64:将启用 64 位 JVM
-Xms512m:将初始堆大小设置为 512 MB
-Xmx4g:将最大堆大小设置为 4 GB
(这里java文件名为:HelloWorld.java)
java -d64 -Xms512m -Xmx4g HelloWorld
where,
-d64: Will enable 64-bit JVM
-Xms512m: Will set initial heap size as 512 MB
-Xmx4g: Will set maximum heap size as 4 GB
(here java file name is : HelloWorld.java)
请使用以下命令将堆大小更改为 6GB
Please use below command to change heap size to 6GB
是的,你可以。事实上,如果您愿意,您可以增加到超过物理内存量。
这样做是否是一个好主意取决于系统上正在运行的其他程序。特别是,如果当前运行的应用程序和服务的“工作集”显着超过可用物理内存,您的系统很容易“崩溃”,花费大量时间将虚拟内存页面移入磁盘或从磁盘移出。最终的结果是系统变得非常慢。
Yes you can. In fact, you can increase to more than the amount of physical memory, if you want to.
Whether it is a good idea to do this depends on how much else is running on your system. In particular, if the "working set" of the applications and services that are currently running significantly exceeds the available physical memory, your system is liable to "thrash", spending a lot of time moving virtual memory pages to and from disk. The net effect is that the system gets horribly slow.
有几个人通过
-Xms
和-Xms
的jvm选项指出了堆大小的具体答案。我想指出的是,这并不是 jvm 的唯一内存选项类型。具体来说,如果您的堆栈溢出,那么您将需要通过添加诸如-Xss8m
之类的附加选项来增加堆栈的大小。对于这个问题,类似
-Xms2g -Xmx6g -Xss8m
的 jvm 选项将是一个解决方案。我分享这些信息是因为我在谷歌搜索如何增加 jvm 内存时找到了这个解决方案,并且该解决方案不适用于大量内存分配。一旦我弄清楚具体设置的用途,我就可以通过谷歌搜索如何增加堆栈大小并找到丢失的参数。 :) 希望这可以节省其他人的时间,就像它可以节省我大量的时间一样。 :)
Several people pointed out the specific answers for heap size with the jvm options of
-Xms
and-Xms
. I want to point out that this is not the only type of memory options for the jvm. Specifically if you are get stack over flows, then you'll want to increase the size of the stack by adding an additional option like-Xss8m
.For this problem, the jvm options of something like
-Xms2g -Xmx6g -Xss8m
would be a solution.I'm sharing this information as my google searches on how to increase jvm memory took me to this solution, and the solutions didn't work with high amounts of memory allocation. Once I figured out what the specific settings were for, I was able to google how to increase the stack size and found the missing param. :) Hope this saves others time, as it would of saved me a ton of time. :)
这仅适用于 64 位版本的 Java。转到控制面板并单击 Java 图标。在Java控制面板的小窗口中,单击Java菜单栏,然后单击
查看
按钮。如果您有两个 Java 平台,请禁用以前版本的 Java,然后单击“运行时参数”文本字段并写入
-Xmx1024m
或小于 RAM 大小。不要将堆大小增加到等于 RAM,否则系统会崩溃。This only works with 64 bit version of Java. Go to Control Panel and click on the Java icon. On the small window of Java Control Panel, click on the Java menu bar and then click on
view
button.If you have two Java platforms, disable the previous version of Java, then click on Runtime parameters text field and write
-Xmx1024m
or less than RAM size. Don't increase heap size equal to RAM otherwise your system will crash.我不知道为什么没有一个答案提到这一点(可能是因为这个问题很老),但是从Java 8开始,有三个专用的JVM选项来控制堆大小作为可用内存的一部分,这非常有用,特别是对于容器化应用程序。
这些选项是:
-XX:InitialRAMPercentage=percent
InitialRAMPercentage JVM 参数允许我们配置 Java 应用程序的初始堆大小。它是物理服务器或容器总内存的百分比。
-XX:MaxRAMPercentage=percent
MaxRAMPercentage 参数允许为运行大量内存(大于 200 MB)的 JVM 设置最大堆大小。
这是可用于问题中提到的情况的选项:
-XX:MinRAMPercentage=percent
与它的名称不同,允许为运行少量内存的 JVM 设置最大堆大小(小于 200MB)。
有关更多详细信息,请查看这篇文章: https://www.baeldung.com/java -jvm-parameters-rampercentage。
I don't know why none of the answers mention this (probably because the question is old), but starting from Java 8, there are three dedicated JVM options to control the heap size as a fraction of the available memory, which are very useful, especially for containerized applications.
These options are:
-XX:InitialRAMPercentage=percent
The InitialRAMPercentage JVM parameter allows us to configure the initial heap size of the Java application. It’s a percentage of the total memory of a physical server or container.
-XX:MaxRAMPercentage=percent
The MaxRAMPercentage parameter allows setting the maximum heap size for a JVM running with a large amount of memory (greater than 200 MB).
This is the option that can be used for the case mentioned in the question:
-XX:MinRAMPercentage=percent
Unlike its name, allows setting the maximum heap size for a JVM running with a small amount of memory (less than 200MB).
For more details, check out this article: https://www.baeldung.com/java-jvm-parameters-rampercentage.
是的。可以。
您可以将堆内存增加到物理内存(6 GB 堆)的 75% 或更高。
由于您使用的是 64 位,因此您可以将堆大小增加到您想要的量。如果您使用的是 32 位,则限制为 4GB。
将初始堆大小设置为 512mb,最大堆大小设置为 6GB。
希望它有帮助..:)
Yes. You Can.
You can increase your heap memory to 75% of physical memory (6 GB Heap) or higher.
Since You are using 64bit you can increase your heap size to your desired amount. In Case you are using 32bit it is limited to 4GB.
Sets you with initial heap size to 512mb and maximum heapsize to 6GB.
Hope it Helps.. :)
我在使用 eclipse/STS 运行 java 代码中的 py 文件时遇到问题,由于 jvm 堆内存不足而出现 PyException。我已完成如下所述的更改,并且能够解决此问题。以下是我的系统配置。
这些是我在工作区中所做的更改,瞧,它现在运行完美。
I have problem running the py files in my java code using eclipse/STS, getting PyException due to insufficient jvm heap memory. I have done the changes as mentioned below and I'm able to resolve this issue. Below is my System configuration.
And these are the changes I did in my workspace and voila it runs perfect now.
如果有人想知道如何在 Windows 中执行此操作,请执行以下步骤。
Here are the steps if someone wants to know how to do this in windows.