Linux 无法更改 tomcat 7 堆大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6398053/
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
Can't change tomcat 7 heap size
提问by Mahmoud Saleh
I have set the heap size of tomcat 7 by adding the following line in catalina.sh
我通过添加以下行来设置 tomcat 7 的堆大小 catalina.sh
export CATALINA_OPTS="-Xms512m -Xmx1024m"
then stopped and started the tomcat. but when tried to get the heap size using the command jmap -heap , i can notice that the memory doesn't change:
然后停止并启动tomcat。但是当尝试使用命令 jmap -heap 获取堆大小时,我可以注意到内存没有改变:
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 526385152 (502.0MB)
NewSize = 1048576 (1.0MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 67108864 (64.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 99352576 (94.75MB)
used = 9643144 (9.196418762207031MB)
free = 89709432 (85.55358123779297MB)
9.705982862487632% used
From Space:
capacity = 4063232 (3.875MB)
used = 0 (0.0MB)
free = 4063232 (3.875MB)
0.0% used
To Space:
capacity = 5177344 (4.9375MB)
used = 0 (0.0MB)
free = 5177344 (4.9375MB)
0.0% used
PS Old Generation
capacity = 37748736 (36.0MB)
used = 21889008 (20.874984741210938MB)
free = 15859728 (15.125015258789062MB)
57.98606872558594% used
PS Perm Generation
capacity = 60948480 (58.125MB)
used = 31496008 (30.03693389892578MB)
free = 29452472 (28.08806610107422MB)
51.67644541750672% used
please advise.
请指教。
采纳答案by Omnaest
回答by Ali Irawan
Goto your catalina.sh
转到你的 catalina.sh
Add these line at the beginning
在开头添加这些行
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server -Xms512m -Xmx1024m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"
Then start your tomcat using startup.sh
然后使用startup.sh启动你的tomcat
回答by o?????
Do not change catalina.sh
!!This file is not supposed to be changed by user. Tomcat updates may override it. Instead create a file called "setenv.sh" in your "$CATALINA_BASE/bin" (same folder as catalina.sh
). Set all your environment variables there.
不要改变catalina.sh
!!用户不应更改此文件。Tomcat 更新可能会覆盖它。而是在您的“$CATALINA_BASE/bin”(与 相同的文件夹)中创建一个名为“ setenv.sh”的文件catalina.sh
。在那里设置所有环境变量。
setenv.sh
is an optional file. If it exists it gets imported by catalina.sh
. And the name suggests what you put there. This is a proper place to initialize your $CATALINA_OPTS, $JAVA_OPTS, etc.
setenv.sh
是一个可选文件。如果它存在,它会被导入catalina.sh
。这个名字暗示了你放在那里的东西。这是初始化 $CATALINA_OPTS、$JAVA_OPTS 等的合适位置。
P.S. Generally speaking you should avoid tweaking files that can can change with package/distribution update provided and alternative configuration approach exists. In this case files like catalina.sh
, /etc/tomcat7/tomcat7.conf
, /etc/init.d/tomcatX
etc can be updated silently and you won't even notice that your configuration changes are rolled back.
PS 一般来说,您应该避免调整可以随包/发行版更新而更改的文件,并且存在替代配置方法。在这种情况下的文件一样catalina.sh
,/etc/tomcat7/tomcat7.conf
,/etc/init.d/tomcatX
等可以静默更新,你甚至不会通知您的配置更改将回滚。
回答by spanky
sudo vi /etc/default/tomcat7
Find the line that begins JAVA_OPTS="-Djava.awt.headless=true
找到开始的行 JAVA_OPTS="-Djava.awt.headless=true
and change the piddly -Xmx128m
to -Xms512m -Xmx1024m
并更改-Xmx128m
为-Xms512m -Xmx1024m
If you have more than one core...-XX:+UseConcMarkSweepGC
is probably what you want.
如果您有多个核心……-XX:+UseConcMarkSweepGC
可能就是您想要的。
回答by Arash Joorabchi
how about editing etc/default/tomcat7
如何编辑 etc/default/tomcat7
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
JAVA_OPTS="-Djava.awt.headless=true -Xmx1280m -XX:+UseConcMarkSweepGC"