java.lang.OutOfMemoryError: PermGen space
I found that many people attribute the problem to: spring, hibernate, tomcat, because they dynamically generate classes, causing the permanent heap in the JVM to overflow. Then there are different solutions. Some people say to upgrade the tomcat version to the latest version or even not use tomcat at all. Some people also doubt spring's problems, and the discussion on the spring forum is very intense, because spring uses CBLIB in AOP to dynamically generate many classes.
But the question is why these ace open source products have the same problem. Is it a more basic reason? Tomcat answered this point very implicitly in the Q&A. We are aware of this problem, but this question arises from a more basic question.
So someone checked the more basic JVM and found the key to 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 frequently used classes and class descriptions. When SUN originally designed it, he thought that this area would be fixed when the JVM started, but he did not expect that dynamic would be so widely used now. Moreover, this area has a special garbage collection mechanism. The problem now is that after dynamically loading classes into this area, GC cannot collect them at all!
1. The first is: java.lang.OutOfMemoryError: Java heap space
Explanation:
Heap size setting
The JVM heap setting refers to java During the running of the program, the JVM can allocate the settings of the memory space used. The JVM will automatically set the Heap size value when it is started. Its initial space (i.e. -Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of physical memory. You can use the -Xmn -Xms -Xmx and other options provided by the JVM to set it. The size of Heap size is the sum of Young Generation and Tenured Generation.
Tip: In the JVM, if 98% of the time is used for GC and the available Heap size is less than 2%, this exception message will be thrown.
Tip: The Heap Size should not exceed 80% of the available physical memory. Generally, the -Xms and -Xmx options should be set to the same value, and -Xmn should be 1/4 of the -Xmx value.
Solution:
Manually set Heap size
Modify TOMCAT_HOME/bin/catalina.bat and add the following line above "echo "Using CATALINA_BASE: $CATALINA_BASE"":
set JAVA_OPTS=%JAVA_OPTS% -server -Xms800m -Xmx800m -XX:MaxNewSize=256m
Or modify catalina.sh
Add the following line above "echo "Using CATALINA_BASE: $CATALINA_BASE"":
JAVA_OPTS="$JAVA_OPTS -server -Xms800m -Xmx800m -XX:MaxNewSize=256m" [html] 2、其次是:java.lang.OutOfMemoryError: PermGen space 原因: PermGen space的全称是Permanent Generation space,是指内存的永久保存区域,这块内存主要是被JVM存放Class和Meta信息的,Class在被Loader时就会被放到PermGen space中,它和存放类实例(Instance)的Heap区域不同,GC(Garbage Collection)不会在主程序运行期对PermGen space进行清理,所以如果你的应用中有很CLASS的话,就很可能出现PermGen space错误,这种错误常见在web服务器对JSP进行pre compile的时候。如果你的WEB APP下都用了大量的第三方jar, 其大小超过了jvm默认的大小(4M)那么就会产生此错误信息了。 解决方法: 1. 手动设置MaxPermSize大小 修改TOMCAT_HOME/bin/catalina.bat(Linux下为catalina.sh),在 [code] “echo "Using CATALINA_BASE: $CATALINA_BASE"”上面加入以下行: set JAVA_OPTS=%JAVA_OPTS% -server -XX:PermSize=128M -XX:MaxPermSize=512m
catalina.sh is as follows:
JAVA_OPTS="$JAVA_OPTS -server -XX:PermSize=128M -XX:MaxPermSize=512m"
More jvm memory overflow solution (how to solve jvm memory overflow) related articles please pay attention to the PHP Chinese website!