tomcat PermGen space exception, OOM exception

Exception : I encountered a problem that the system stopped responding in the project. Looking at the log, I found that Tomcat reported Caused by: java.lang.OutOfMemoryError: PermGen space exception. At first I thought it was a memory overflow caused by a program memory leak. I checked it online and it turned out to be something else The reason, but it is indeed a memory overflow.

    Reason : The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​memory.
This memory is mainly used by JVM to store Class and Meta information. When Class is loaded by Loader, it will be placed
in PermGen space. The Heap area of ​​the class instance (Instance) is different, and the GC (Garbage Collection) will not
clean up the PermGen space during the running of the main program, so if your application has a lot of CLASS, it is likely to appear PermGen
space error, this kind of error It is common when the web server pre-compiles the JSP. If your WEB APP uses a large
number of third-party jars, the size of which exceeds the default size of jvm (4M), then this error message will be generated.

    Here are the various claims on the Internet:

    (1) This is a memory leak caused by Tomcat's unstable hot publisher / hot deployer. It is recommended to turn off the autopublishing function of the server configuration in Eclipse , and then manually restart Tomcat , or remove those items that are no longer needed in the webapps file of tomcat .    (2) It is found that many people attribute the problem to: spring, hibernate, tomcat, because they generate classes dynamically, which leads to the overflow of the permanent heap in the JVM. Then there are different solutions. Some people say to upgrade the tomcat version to the latest or even not to use tomcat at all. There are also people who suspect the problem of spring, and the discussion on the spring forum is very intense, because spring uses CBLIB to dynamically generate many classes in AOP.

 
But the question is why these ace open source have the same problem, so is it a more basic reason? tomcat answers this vaguely in the Q&A, we know the question, but the question arises from a more fundamental question.    
 
    So someone checked the more basic JVM and found the crux of the problem. It turns out that SUN's JVM divides the memory into different areas, one of which is the permenter area, which is used to store the classes and class descriptions that are used a lot. Originally, SUN thought that this area was fixed when the JVM was started, but he did not expect that the dynamic would be used so widely now. And this area has a special garbage collection mechanism. The problem now is that after dynamically loading classes into this area, gc can't collect them at all! In 2003, a bug was reported to sun, but until now, this bug has not been closed! Someone added a comment to this bug: "A bug this critical is open since 2003? Absolutely shameful."
 
(3) It's usually happened when the Tomcat start and stop few times. It's just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, you should increase the memory by make change in catalina.sh or catalina.bat file.    

   Workaround : Manually set the MaxPermSize size

   Set parameters -Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m

In Tomcat, modify TOMCAT_HOME/bin/catalina.sh (start.sh under linux system will call it to start tomcat, under windows call catalina.bat, the modification is similar)

在文件头部注释后加入
JAVA_OPTS='-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m'
如果tomcat运行多个系统,将相同的第三方jar文件移置到tomcat/shared/lib目录下,这样可以达到减少
jar 文档重复占用内存的目的。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325490544&siteId=291194637