關於PermGen space內存溢出錯誤解決方法


1.參考:

http://blog.csdn.net/fox009/article/details/5633007

http://hi.baidu.com/like_dark/blog/item/19c1948b3292b0799f2fb468.html

http://anyeeye.iteye.com/blog/444624

Tomcat6性能調優 出現java.lang.OutOfMemoryError: PermGen space

http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/

https://blog.csdn.net/xw13106209/article/details/6996976

http://outofmemory.cn/c/java-outOfMemoryError

 

2.報錯:

 

[java]  view plain  copy
 
  1. Exception in thread "DispatcherThread" java.lang.OutOfMemoryError: PermGen space  
  2. Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space  
  3. Exception in thread "State Saver" java.lang.OutOfMemoryError: PermGen space  
  4. Exception in thread "AWT-Windows" java.lang.OutOfMemoryError: OutOfMemoryError  

3.原因:

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)那么就會產生此錯誤信息了。

4.解決方法1: 

手動設置MaxPermSize大小,如果是linux系統,修改TOMCAT_HOME/bin/catalina.sh,如果是windows系統,修改TOMCAT_HOME/bin/catalina.bat,
在“echo "Using CATALINA_BASE: $CATALINA_BASE"”上面加入以下行:
JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m
建議:將相同的第三方jar文件移置到tomcat/shared/lib目錄下,這樣可以達到減少jar 文檔重復占用內存的目的。

如果依然不行,請改為

JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=512m

5.解決方法2

修改eclipse.ini文件,修改如下:

 

[java]  view plain  copy
 
  1. -vmargs  
  2. -Dosgi.requiredJavaVersion=1.5  
  3. -Xms128m  
  4. -Xmx512m  
  5. -XX:PermSize=64M   
  6. -XX:MaxPermSize=128M  

如果還報錯,可以考慮如下修改

 

 

[java]  view plain  copy
 
  1. -vmargs  
  2. -Dosgi.requiredJavaVersion=1.5  
  3. -Xms512m  
  4. -Xmx1024m  
  5. -XX:PermSize=256M   
  6. -XX:MaxPermSize=512M  

 

報錯:

 

[java]  view plain  copy
 
  1. 2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc  
  2. 嚴重: The web application [/Application] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.  
  3. 2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads  
  4. 嚴重: The web application [/Application] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.  
  5. 2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads  
  6. 嚴重: The web application [/Application] appears to have started a thread named [AWT-Windows] but has failed to stop it. This is very likely to create a memory leak.  
  7. 2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads  
  8. 嚴重: The web application [/Application] appears to have started a thread named [Thread-14] but has failed to stop it. This is very likely to create a memory leak.  
  9. 2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap  
  10. 嚴重: The web application [/Application] created a ThreadLocal with key of type [net.sf.json.AbstractJSON$1] (value [net.sf.json.AbstractJSON$1@3661eeb]) and a value of type [java.util.HashSet] (value [[]]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.  
  11. 2011-11-21 21:10:50 org.apache.catalina.core.ApplicationContext log  
  12. 信息: Initializing Spring FrameworkServlet 'Dispatcher'  



 

修改catalina.bat

添加

 

[java]  view plain  copy
 
  1. JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8   
  2. -server -Xms1536m -Xmx1536m  
  3. -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m   
  4. -XX:MaxPermSize=256m -XX:+DisableExplicitGC"  


樣例

 

[java]  view plain  copy
 
  1. #   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension  
  2. #                   (JSSE) installation, whose JAR files will be added to the  
  3. #                   system class path used to start Tomcat.  
  4. #  
  5. #   CATALINA_PID    (Optional) Path of the file which should contains the pid  
  6. #                   of catalina startup java process, when start (fork) is used  
  7. #  
  8. # $Id: catalina.sh 609438 2008-01-06 22:14:28Z markt $  
  9. # -----------------------------------------------------------------------------  
  10.    
  11. JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m   
  12. -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m   
  13. -XX:MaxPermSize=256m -XX:+DisableExplicitGC"  
  14.    
  15.    
  16. # OS specific support.  $var _must_ be set to either true or false.  
  17. cygwin=false  
  18. os400=false  
  19. darwin=false  
  20. case "`uname`" in  
  21. CYGWIN*) cygwin=true;;  
  22. OS400*) os400=true;;  
  23. Darwin*) darwin=true;;  
  24. esac  
  25.    
  26. # resolve links - $0 may be a softlink  
  27. PRG="$0"  



具體參數根據自己機器情況而定

 

[java]  view plain  copy
 
    1. JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m   
    2. -Xmx512m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m   
    3. -XX:MaxPermSize=256m -XX:+DisableExplicitGC"  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM