如何减少Java堆大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23609711/
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
How to decrease java heap size?
提问by Tony
I've got an app which is running on JBoss
. The server's RAM is too low (about 2gb), so I need to decrease Java
heap size. Also I've got 2 versions of Java : system version(1.4.2
) and 1.7.0
for JBoss 7
only.
So, how can I decrease Java heap size properly?
我有一个正在运行的应用程序JBoss
。服务器的 RAM 太低(大约 2GB),所以我需要减小Java
堆大小。此外,我有 2 个版本的 Java: system version( 1.4.2
) 和1.7.0
for JBoss 7
only。那么,如何正确减少 Java 堆大小?
采纳答案by mohansaravanan
You can change the heap size in jboss startup file, edit bat or sh file and search for -Xms and change it to your required size.
您可以在 jboss 启动文件中更改堆大小,编辑 bat 或 sh 文件并搜索 -Xms 并将其更改为您需要的大小。
回答by dcsohl
There are two flags to control the heap size: -Xms128m will startyour heap at 128 megs, and -Xmx1g controls the maximum size (here, it would set it to 1 gig).
有两个标志可以控制堆大小:-Xms128m 将以128 megs开始您的堆,而 -Xmx1g 控制最大大小(在这里,它将设置为 1 gig)。
回答by Owen Cao
Default size of Heap space in Java is 128MB on most of 32 bit Sun's JVM and default values of heap size parameters on 64-bit systems have been increased up by approximately 30%.
Java 中堆空间的默认大小在大多数 32 位 Sun 的 JVM 上为 128MB,而在 64 位系统上堆大小参数的默认值增加了大约 30%。
You can use
您可以使用
java -XX:+PrintFlagsFinal -version | grep HeapSize
to check your default size.
检查您的默认尺寸。
You can change size of heap space by using JVM options -Xms and -Xmx. Xms denotes starting size of Heap while -Xmx denotes maximum size of Heap in Java.
You can use
java -Xms1024M -Xmx2048M YourApp
您可以使用 JVM 选项 -Xms 和 -Xmx 更改堆空间的大小。Xms 表示堆的起始大小,而 -Xmx 表示 Java 中堆的最大大小。
您可以使用
java -Xms1024M -Xmx2048M YourApp
Or edit the /bin/run.sh|exe file by searching for “Sun JVM memory allocation pool parameters” and changing the JAVA_OPTS line:
或者通过搜索“Sun JVM 内存分配池参数”并更改 JAVA_OPTS 行来编辑 /bin/run.sh|exe 文件:
set JAVA_OPTS=%JAVA_OPTS% -server -Xms1152m -Xmx1152m -XX:MaxPermSize=128m -XX:MaxNewSize=128m
设置 JAVA_OPTS=%JAVA_OPTS% -server -Xms1152m -Xmx1152m -XX:MaxPermSize=128m -XX:MaxNewSize=128m