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日志如下:

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还是蛮关键的!!

 

你可能感兴趣的:(web)