在 Java 中增加堆大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1565388/
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
Increase heap size in Java
提问by Sunil
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)?
我正在使用 8 GB RAM 的 Windows 2003 服务器(64 位)。如何增加堆内存最大值?我正在使用该-Xmx1500m
标志将堆大小增加到 1500 Mb。我可以将堆内存增加到物理内存的 75%(6 GB 堆)吗?
采纳答案by Steve B.
You can increase to 4GB on a 32 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.
您可以在 32 位系统上增加到 4GB。如果您使用的是 64 位系统,则可以更高。如果您选择错误,无需担心,如果您在 32 位系统上要求 5g,java 会抱怨无效值并退出。
As others have posted, use the cmd-line flags - e.g.
正如其他人发布的那样,使用 cmd-line 标志 - 例如
java -Xmx6g myprogram
You can get a full list (or a nearly full list, anyway) by typing java -X.
您可以通过键入 java -X 获得完整列表(或几乎完整的列表)。
回答by Stephen C
Can I increase the heap memory to 75% of physical memory(6GB Heap).
我可以将堆内存增加到物理内存(6GB 堆)的 75%。
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.
这样做是否是一个好主意取决于您的系统上正在运行的其他内容。特别是,如果当前运行的应用程序和服务的“工作集”明显超过可用物理内存,您的系统很容易“崩溃”,花费大量时间将虚拟内存页面移入和移出磁盘。最终的结果是系统变得非常缓慢。
回答by Kevin
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:
在 32 位 JVM 上,理论上可以设置的最大堆大小是 4gb。要使用更大的堆大小,您需要使用 64 位 JVM。请尝试以下操作:
java -Xmx6144M -d64
java -Xmx6144M -d64
The -d64 flag is important as this tells the JVM to run in 64-bit mode.
-d64 标志很重要,因为它告诉 JVM 在 64 位模式下运行。
回答by Karthik Reddy
It is possible to increase heap size allocated by the JVM by using command line options Here we have 3 options
可以使用命令行选项增加 JVM 分配的堆大小 这里我们有 3 个选项
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
java -Xms16m -Xmx64m ClassName
In the above line we can set minimum heap to 16mb and maximum heap 64mb
在上面的行中,我们可以将最小堆设置为 16mb,将最大堆设置为 64mb
回答by Karthik Reddy
It is possible to increase heap size allocated by the JVM in eclipse directly In eclipse IDE goto
可以直接在eclipse中增加JVM分配的堆大小在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)
输入 -Xmx1g(用于设置最大尺寸,如 Xmx256m 或 Xmx1g...... m-->mb g--->gb)
回答by Sumit Deshinge
java -d64 -Xms512m -Xmx4g HelloWorld
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)
其中,-d64:将启用 64 位 JVM -Xms512m:将初始堆大小设置为 512 MB -Xmx4g:将最大堆大小设置为 4 GB(这里的 java 文件名是:HelloWorld.java)
回答by madhu
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.
这仅适用于 64 位版本的 Java。转到控制面板并单击 Java 图标。在 Java 控制面板的小窗口中,单击 Java 菜单栏,然后单击view
按钮。
If you have two Java platforms, disable the previous version of Java, then click on Runtime parameterstext field and write -Xmx1024m
or less than RAM size. Don't increase heap size equal to RAM otherwise your system will crash.
如果您有两个 Java 平台,请禁用以前版本的 Java,然后单击运行时参数文本字段并写入-Xmx1024m
或小于 RAM 大小。不要增加等于 RAM 的堆大小,否则您的系统会崩溃。
回答by madhu
Please use below command to change heap size to 6GB
请使用以下命令将堆大小更改为 6GB
export JAVA_OPTS="-Xms6144m -Xmx6144m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m"
回答by Sarat Chandra
Yes. You Can.
是的。你可以。
You can increase your heap memory to 75% of physical memory (6 GB Heap) or higher.
您可以将堆内存增加到物理内存(6 GB 堆)的 75% 或更高。
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.
由于您使用的是 64 位,因此您可以将堆大小增加到所需的数量。如果您使用的是 32 位,则限制为 4GB。
$ java -Xms512m -Xmx6144m JavaApplication
Sets you with initial heap size to 512mb and maximum heapsize to 6GB.
将初始堆大小设置为 512mb,将最大堆大小设置为 6GB。
Hope it Helps.. :)
希望能帮助到你.. :)
回答by James Oravec
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
.
一些人指出,为堆大小与JVM选项的具体答案-Xms
和-Xms
。我想指出这不是 jvm 的唯一内存选项类型。具体来说,如果您获得堆栈溢出流,那么您将需要通过添加一个额外的选项来增加堆栈的大小,如-Xss8m
.
For this problem, the jvm options of something like -Xms2g -Xmx6g -Xss8m
would be a solution.
对于这个问题,类似的 jvm 选项-Xms2g -Xmx6g -Xss8m
将是一个解决方案。
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. :)
我正在分享此信息,因为我的 google 搜索如何增加 jvm 内存将我带到此解决方案,并且这些解决方案在大量内存分配下不起作用。一旦我弄清楚了特定设置的用途,我就可以通过谷歌搜索如何增加堆栈大小并找到丢失的参数。:) 希望这可以节省其他人的时间,因为它可以为我节省大量时间。:)