在看下文之前,首先要確認意見事情,就是你是如何啟動tomcat的,我們在平時的開發(fā)環(huán)境當中,都是通過startup.bat方式啟動tomcat的,那么你按照下面的方式,去修改/bin/catalina.bat是沒有問題的。但是如果你是生產(chǎn)環(huán)境下,我們一般都希望使用windows服務(wù)方式去啟動tomcat,此時之前修改的配置文件是沒有用的。因為windows服務(wù)啟動tomcat不再去加載catalina.bat當中的參數(shù)了,而是去加載注冊表中的參數(shù),所以我們需要修改注冊表。
HKEY_LOCAL_MACHINE/SOFTWARE/Apache Software Foundation/Procrun 2.0/Tomcat_APPNAME/Parameters/Java,修改JvmMs和JvmMx的值,當前我都將其設(shè)定為1024,也就是1個G的容量。具體性能再后面繼續(xù)觀察。 之前還真不知道windows服務(wù)啟動和startup.bat啟動的區(qū)別。 windows服務(wù)器啟動是在注冊表中加載參數(shù),startup.bat啟動是在catalina.bat加載參數(shù)。
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性能調(diào)優(yōu) 出現(xiàn)java.lang.OutOfMemoryError: PermGen space
http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/
Exception in thread "DispatcherThread" java.lang.OutOfMemoryError: PermGen spaceException in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen spaceException in thread "State Saver" java.lang.OutOfMemoryError: PermGen spaceException in thread "AWT-Windows" java.lang.OutOfMemoryError: OutOfMemoryError
PermGen space的全稱是Permanent Generation space,是指內(nèi)存的永久保存區(qū)域,這塊內(nèi)存主要是被JVM存放Class和Meta信息的,Class在被Loader時就會被放到PermGen space中,它和存放類實例(Instance)的Heap區(qū)域不同,GC(Garbage Collection)不會在主程序運行期對PermGen space進行清理,所以如果你的應(yīng)用中有很多CLASS的話,就很可能出現(xiàn)PermGen space錯誤,這種錯誤常見在web服務(wù)器對JSP進行pre compile的時候。如果你的WEB APP下都用了大量的第三方j(luò)ar, 其大小超過了jvm默認的大小(4M)那么就會產(chǎn)生此錯誤信息了。
手動設(shè)置MaxPermSize大小,如果是linux系統(tǒng),修改TOMCAT_HOME/bin/catalina.sh,如果是windows系統(tǒng),修改TOMCAT_HOME/bin/catalina.bat,
在“echo "Using CATALINA_BASE: $CATALINA_BASE"”上面加入以下行:
JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m
建議:將相同的第三方j(luò)ar文件移置到tomcat/shared/lib目錄下,這樣可以達到減少jar 文檔重復(fù)占用內(nèi)存的目的。
修改eclipse.ini文件,修改如下:
如果還報錯,可以考慮如下修改
報錯:
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=falseos400=falsedarwin=falsecase "`uname`" inCYGWIN*) cygwin=true;;OS400*) os400=true;;Darwin*) darwin=true;;esac # resolve links - $0 may be a softlinkPRG="$0"
具體參數(shù)根據(jù)自己機器情況而定
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"