Tomcat-警惕内存溢出

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.

扫描二维码关注公众号,回复: 1180595 查看本文章

 

To set the environment variable on Windows, create a setenv.bat manually, and put it into the ${tomcat-folder}\binfolder.

 

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之后的状态对比:

初始时

 

设置后



 

 

猜你喜欢

转载自just2learn.iteye.com/blog/2068761
今日推荐