Tomcat 6.0.32 +Spring dbcp datasource关闭Tomcat出现严重异常

异常如下:

信息: Pausing Coyote HTTP/1.1 on http-
-- :: org.apache.catalina.core.StandardService stop
信息: Stopping service Catalina
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/tsmanager] 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.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/tsmanager] appears to have started a thread named [scheduler_Worker-] but has failed to stop it. This is very likely to create a memory leak.
-- :: org.apache.coyote.http11.Http11Protocol destroy
信息: Stopping Coyote HTTP/1.1 on http-
[QC] INFO [main] org.springframework.context.support.AbstractApplicationContext.doClose() | Closing Root WebApplicationContext: startup date [Thu Mar :: CST ]; root of context hierarchy
[QC] INFO [main] org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.stop() | Stopping beans in phase
[QC] INFO [main] org.quartz.core.QuartzScheduler.standby() | Scheduler scheduler_$_yanshiying-PC1394088762202 paused.
[QC] INFO [main] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons() | Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ac7fbb: defining beans [dataSource,jdbcTemplate,xxtsService,wpushDao,httpUtil,cronService,clearDataJob,getNsrInfoJob,scheduler,quartzManager]; root of factory hierarchy
[QC] INFO [main] org.springframework.scheduling.quartz.SchedulerFactoryBean.destroy() | Shutting down Quartz Scheduler
[QC] INFO [main] org.quartz.core.QuartzScheduler.shutdown() | Scheduler scheduler_$_yanshiying-PC1394088762202 shutting down.
[QC] INFO [main] org.quartz.core.QuartzScheduler.standby() | Scheduler scheduler_$_yanshiying-PC1394088762202 paused.
[QC] INFO [main] org.quartz.core.QuartzScheduler.shutdown() | Scheduler scheduler_$_yanshiying-PC1394088762202 shutdown complete.

Tomcat版本为:6.0.32

spring数据源配置如下:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/wzhpush"/>
<property name="username" value="root"/>
<property name="password" value="mysqladmin"/>
</bean>

原因:https://issues.apache.org/jira/browse/DBCP-332

BasicDataSource's method close() doesn't deregister JDBC driver. This causes permgen memory leaks in web server environments, during context reloads. For example, using Tomcat 6.0.26 with Spring, and BasicDataSource declared in Spring context, there is a message printed at web application reload:

SEVERE: A web application registered the JBDC 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.

解决方法:

import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.commons.dbcp.BasicDataSource; /**
* 解决 关闭Tomcat时报错:the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped
* @author*/
public class WzhBasicDataSource extends BasicDataSource{
@Override
public synchronized void close() throws SQLException {
DriverManager.deregisterDriver(DriverManager.getDriver(url));
super.close();
}
}
上一篇:VS2008 Windows Form项目安装包生成详解


下一篇:HDU 2152 Fruit (母函数)