OutOfMemoryError: PermGen Space
先提供解决办法
Solution
By default, Tomcat is assigned a very little PermGen memory for the running process. To fix it, increase the PermGen memory settings by using the following Java VM options.
-XX:PermSize<size> - Set initial PermGen Size. -XX:MaxPermSize<size> - Set the maximum PermGen Size.
In the next step, we will show you how to set the VM options in Tomcat, under Windows and Linux environment.
Windows
Tomcat is managed by this script file catalina.bat
, dive inside the script, you will find out that catalina.bat
always find and run the setenv.bat
file to set the environment variables.
To set the environment variable on Windows, create a setenv.bat
manually, and put it into the ${tomcat-folder}\bin
folder.
set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m
Restart Tomcat, it will call the setenv.bat
file to set the environment variable automatically.
如果设置后启动Tomcat控制台输出乱码,是因为CMD窗口的编码不是UTF-8导致的。
将上面的file.encoding改为GBK即可。
Linux
On Linux, the process is same, just Tomcat is using catalina.sh
and setenv.sh
instead.
Find out where is catalina.sh
:
$ sudo find / -name "catalina.sh"
Review the catalina.sh
, script, it behaves like Windows, but use setenv.sh
instead.
Create a setenv.sh
manually, and put it into the ${tomcat-folder}\bin\
folder.
${tomcat-folder}\bin\setenv.sh
export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m"
Restart Tomcat.
下面2个截图是Tomcat7启动后的初始内存使用状态,与设置setenv之后的状态对比:
设置后