Tomcat启动报错java.lang.OutOfMemoryError: PermGen space

参考:https://blog.csdn.net/aaa1050070637/article/details/83011384

1.java.lang.OutOfMemoryError: PermGen space

(一)原因分析

今天将另一台电脑上的项目拷贝到其他电脑上面,报错,很奇怪在另一台电脑上是可以运行的,拷贝到本机之后不可以了(连同Tomcat一起拷贝的),最后分析了一下Caused by: java.lang.OutOfMemoryError: PermGen space,可能是内存溢出,解决方法也一定是加大内存,

PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决方法也一定是加大内存。说说为什么会内存益出:这一部分用于存放Class和Meta的信息,Class在被 Load的时候被放入PermGen space区域,它和和存放Instance的Heap区域不同,GC(Garbage Collection)不会在主程序运行期对PermGen space进行清理,所以如果你的APP会LOAD很多CLASS的话,就很可能出现PermGen space错误。这种错误常见在web服务器对JSP进行pre compile的时候。

2019-5-30 10:39:46 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2019-5-30 10:39:46 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2019-5-30 10:39:46 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@d34eb84')
2019-5-30 10:40:55 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'nda.root' = [G:\Tomcat\apache-tomcat-7.0.78\webapps\trunk\]
2019-5-30 10:40:55 org.apache.catalina.core.ApplicationContext log
信息: Initializing log4j from [G:\Tomcat\apache-tomcat-7.0.78\webapps\trunk\WEB-INF\conf\log4j.xml]
2019-5-30 10:40:55 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2019-5-30 10:41:29 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class com.neusoft.talentbase.platform.core.initialization.TBContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paramConfigService' defined in URL [jar:file:/G:/Tomcat/apache-tomcat-7.0.78/webapps/trunk/WEB-INF/lib/tb-platform-console.jar!/com/neusoft/talentbase/platform/console/param/service/ParamConfigServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: PermGen space
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    at com.neusoft.talentbase.platform.core.initialization.TBContextLoaderListener.initWebApplicationContext(TBContextLoaderListener.java:22)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.OutOfMemoryError: PermGen space
    at java.lang.reflect.Proxy.defineClass0(Native Method)
    at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:613)
    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:690)
    at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:117)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:476)

(二)解决方法

1.手动设置MaxPermSize大小修改TOMCAT_HOME/bin/catalina.bat(windows系统)或者catalina.sh(unix系统)
*********************************window系统*************************************
在 TOMCAT_HOME/bin/catalina.bat 文件 echo Using CATALINA_BASE:   "%CATALINA_BASE%"上面加入以下行:

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

************************************Linux/Mac系统********************************
catalina.sh 文件 echo "Using CATALINA_BASE:   $CATALINA_BASE"上面或者第一行加入以下行:

set JAVA_OPTS=%JAVA_OPTS% -server -XX:PermSize=256M -XX:MaxPermSize=512m
捕获.PNG
2.eclipse当中启动Tomcat报错java.lang.OutOfMemoryError: PermGen space

tomcat启动的时候出现这种错误一般是项目引用了太多的jar包,或者反射生成了太多的类,或者有太多的常量池,导致非堆内存中永久保存区域不够,就有可能会报java.lang.OutOfMemoryError: PermGen space的错误,

这种情况可以通过jvm参数-XX:PermSize=256M -XX:MaxPermSize=512m来配置这部分内存的大小(注意:此处内存是不会被java垃圾回收机制进行处理的地方,要合理配置,更不能超出操作系统的可用内存)。

具体设置步骤如下:

1.双击server中配置的tomcat

image

2.点击Open launch configuration

image

3.在打开的窗口中切换到Arguments选项,在VM arguments进行配置

image

到此配置完毕,当然在该区域还可以配置其他JVM参数,比如:初始堆大小(-Xms512m)和最大堆大小(-Xmx512m),

堆内存被jvm的垃圾回收机制管理,为避免在每次GC 后调整堆的大小,浪费资源,

服务器一般设置-Xms、-Xmx相等(默认空余堆内存小于40%时,JVM就会增大堆直到-Xmx的最大限制;空余堆内存大于70%时,JVM会减少堆直到 -Xms的最小限制)

你可能感兴趣的:(Tomcat启动报错java.lang.OutOfMemoryError: PermGen space)