天天看點

tomcat java.lang.OutOfMemoryError: PermGen space

about:[email protected] [email protected]

環境:

centos7.5

tomcat8.5.34  apr 運作模式 

jdk1.7.80

JVM參數:

-server -Xms4096m -Xmx4096m -Xmn1024m 

-XX:PermSize=512M -XX:MaxPermSize=512M -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled 

-XX:+HeapDumpOnOutOfMemoryError -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps 

-Xloggc:/var/log/tomcat/gc.log -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly

-------------------------------------------------

先講一下發生情況,

業務通路時間07-19,所有隻能再此之外時間更新版本,再加上網絡環境特殊化,無法做成自動化更新。是以隻能手動更新

再更新的時候本想着簡單化,直接再tomcat manager reload項目,沒想發生了記憶體溢出。

------------------------------------------------------------

遇到問題不要慌,先看gc日志 再看tomcat日志(gc日志存放需要設定jvm)

首先我知道肯定不是并發數過大導緻記憶體溢出的(發生的時間在非業務時間)

檢視tomcat日志如下:

tomcat java.lang.OutOfMemoryError: PermGen space

12-Nov-2018 21:10:19.566 資訊 [catalina-exec-2097] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/xxxx] has started

12-Nov-2018 21:10:19.742 警告 [catalina-exec-2097] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [/xxxx] registered the JDBC driver [com.ibm.db2.jcc.DB2Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

12-Nov-2018 21:10:19.742 警告 [catalina-exec-2097] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [/xxxx] 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.

12-Nov-2018 21:10:19.743 警告 [catalina-exec-2097] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [/xxxx] appears to have started a thread named [Timer-21] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

------------------------------------------

 java.util.TimerThread.run(Timer.java:505)

12-Nov-2018 21:10:28.715 資訊 [catalina-exec-2097] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

12-Nov-2018 21:10:37.419 資訊 [catalina-exec-2097] com.sun.faces.config.ConfigureListener.contextInitialized 初始化上下文 '/xxxxx' 的 Mojarra 2.0.3 (FCS b03)

12-Nov-2018 21:10:37.856 資訊 [catalina-exec-2097] com.sun.faces.spi.InjectionProviderFactory.createInstance JSF1048:有 PostConstruct/PreDestroy 注釋。标有這些注釋的 ManagedBeans 方法将表示注釋已處理。

java.lang.OutOfMemoryError: PermGen space

------------------------------------------

首先會把連接配接在DB層的連接配接斷開,但提示已經發生記憶體洩露,這裡開發人員要背鍋。

這個時候tomcat在reload 某個項目是直接發生了permGen sapce(永久代),記憶體溢出了。

是以解決辦法有兩種:

----------------------------------------------

1、不背鍋找開發去

2、嘗試修改一下PermSize

----------------------------------------------------------

若tomcat日志沒有這麼明确推薦看gc日志,這個問題隻會發生在jdk1.7下。jdk8 MetaspaceSize替換了perm

---------------------------------------------------

ps:java程式的調優,JVM還是蠻關鍵的!!

繼續閱讀