PermGen space錯誤解決方法

  作項目的時候,忽然遇到的這個問題,當時tomcat開啓了有2個小時,而後點擊頁面的時候出現:PermGen spacehtml

 在網上查找了很久,終於找到了解決辦法。java

轉載:http://www.cnblogs.com/xwdreamer/archive/2011/11/21/2296930.htmlmysql

在看下文以前,首先要確認意見事情,就是你是如何啓動tomcat的,咱們在平時的開發環境當中,都是經過startup.bat方式啓動tomcat的,那麼你按照下面的方式,去修改/bin/catalina.bat是沒有問題的。可是若是你是生產環境下,咱們通常都但願使用windows服務方式去啓動tomcat,此時以前修改的配置文件是沒有用的。由於windows服務啓動tomcat再也不去加載catalina.bat當中的參數了,而是去加載註冊表中的參數,因此咱們須要修改註冊表。linux

HKEY_LOCAL_MACHINE/SOFTWARE/Apache Software Foundation/Procrun 2.0/Tomcat_APPNAME/Parameters/Java,修改JvmMs和JvmMx的值,當前我都將其設定爲1024,也就是1個G的容量。具體性能再後面繼續觀察。 以前還真不知道windows服務啓動和startup.bat啓動的區別。 windows服務器啓動是在註冊表中加載參數,startup.bat啓動是在catalina.bat加載參數。web

1.參考:

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

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

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

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

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

2.報錯:

Exception in thread "DispatcherThread" java.lang.OutOfMemoryError: PermGen space
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space
Exception in thread "State Saver" java.lang.OutOfMemoryError: PermGen space
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 文檔重複佔用內存的目的。

5.解決方法2

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

複製代碼
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms128m
-Xmx512m
-XX:PermSize=64M 
-XX:MaxPermSize=128M
複製代碼

若是還報錯,能夠考慮以下修改

複製代碼
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx1024m
-XX:PermSize=256M 
-XX:MaxPermSize=512M
複製代碼

報錯:

複製代碼
2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
嚴重: 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.
2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
嚴重: 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.
2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
嚴重: 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.
2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
嚴重: 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.
2011-11-21 21:10:46 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
嚴重: 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.
2011-11-21 21:10:50 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'Dispatcher'
複製代碼

修改catalina.bat

添加

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

樣例

複製代碼
#   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension
#                   (JSSE) installation, whose JAR files will be added to the
#                   system class path used to start Tomcat.
#
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
#                   of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh 609438 2008-01-06 22:14:28Z markt $
# -----------------------------------------------------------------------------
 
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m 
-Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"
 
 
# OS specific support.  $var _must_ be set to either true or false.
cygwin=false
os400=false
darwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac
 
# resolve links - $0 may be a softlink
PRG="$0"
複製代碼

具體參數根據本身機器狀況而定

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m 
-Xmx512m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"
相關文章
相關標籤/搜索