tomcat重新部署perm gen space

时间:2016-10-19 05:20:27

标签: java tomcat servlets permgen

我有这些代码用于关闭c3p0连接管理器。没有消息显示有一个线程会导致内存泄漏。但是当我重新部署我的应用程序时,我的perm gen内存不断增加。

Oct 19, 2016 11:05:48 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing WebApplicationContext for namespace 'dispatcherServlet-servlet': startup date [Wed Oct 19 10:41:03 PHT 2016]; parent: Root WebApplicationContext
2016-10-19 11:05:48 - [INFO ] CRMContextListener - Trying to Close
2016-10-19 11:05:53 - [INFO ] CRMContextListener - Close Success
Oct 19, 2016 11:05:53 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Wed Oct 19 10:40:53 PHT 2016]; root of context hierarchy
Oct 19, 2016 11:05:53 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Oct 19, 2016 11:06:03 AM org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/crmdev] has not been started
Oct 19, 2016 11:06:04 AM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/crmdev]

这是我的servlet监听器的代码

public void contextDestroyed(ServletContextEvent sce) {
    logger.info("Trying to Close");

    for (Object o : C3P0Registry.getPooledDataSources()) {
        try {
            ((PooledDataSource) o).close();
        } catch (Exception e) {
            logger.info("No thread was open...");
        }
    }

    logger.info("Close Success");
}

这是我对c3p0的配置

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
    <property name="jdbcUrl" value="jdbc:oracle:thin:@sph-pdc-vm  1042:1521:DEV" />
    <property name="user" value="TSW" />
    <property name="password" value="TSW2015#" />
    <property name="minPoolSize" value="2" />
    <property name="maxPoolSize" value="20" />
    <property name="initialPoolSize" value="5" />
    <property name="testConnectionOnCheckin" value="true" />
    <property name="idleConnectionTestPeriod" value="100" />
    <property name="maxIdleTimeExcessConnections" value="5" />
    <property name="maxStatementsPerConnection" value="10" />
    <property name="acquireIncrement" value="1" />
    <property name="statementCacheNumDeferredCloseThreads" value="1" />
    <property name="acquireRetryAttempts" value="2" />
    <property name="acquireRetryDelay" value="2000" />
</bean>

1 个答案:

答案 0 :(得分:1)

如果您想追踪泄漏,我建议您查看this blog post of mine

如果您只是想摆脱这个问题,请将我的ClassLoader Leak Prevention library添加到您的应用中。

我注意到您使用Oracle JDBC驱动程序known导致这些类型的泄漏。另外,您是否将驱动程序保留在应用程序(WEB-INF/lib)或Tomcat中?