apache-tomcat 7.0.88无故停止问题

使用tomcat 7.0.88发布的java web项目,启动一段时间(大概一天左右)服务会莫名其妙的重启,在后台的catalina.out 查看日志,发现如下一段可以记录:

INFO: Deployment of web application directory /home/apache-tomcat-7.0.88/webapps/manager has finished in 47 ms
Jun 07, 2018 6:35:29 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-80"]
Jun 07, 2018 6:35:29 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 07, 2018 6:35:29 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 14940 ms
Jun 08, 2018 8:35:14 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-80"]
Jun 08, 2018 8:35:14 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Jun 08, 2018 8:35:14 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jun 08, 2018 8:35:14 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing WebApplicationContext for namespace 'spring-servlet': startup date [Thu Jun 07 06:35:21 CST 2018]; parent: Root WebApplicationContext
Jun 08, 2018 8:35:14 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Thu Jun 07 06:35:21 CST 2018]; root of context hierarchy
Jun 08, 2018 8:35:14 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
SEVERE: The web application [] registered the JDBC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jun 08, 2018 8:35:14 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing WebApplicationContext for namespace 'spring-servlet': startup date [Thu Jun 07 06:35:27 CST 2018]; parent: Root WebApplicationContext
Jun 08, 2018 8:35:14 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Thu Jun 07 06:35:27 CST 2018]; root of context hierarchy
Jun 08, 2018 8:35:14 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-80"]
Jun 08, 2018 8:35:14 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Jun 08, 2018 8:35:14 AM org.ap

这句话引起了我的质疑“[oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jun 08, 2018 8:35:14 AM org.springframework.context.support.AbstractApplicationContext doClose”
大概意思是 当web停止的时候,jdbc注销失败,为了防止内存泄漏,jdbc驱动需要强制注销。
但是结果还是停止了,这有可能是强制注销失败,导致了内存泄漏。
查看tomcat官网有如下解释:
因为tomcat自带了DBCP数据库连接池,很多用户在使用DBCP时遇到了这个问题,并建议在 DBCP 的 BasicDataSource的close方法里执行反注册驱动的行为来解决这个警告。但DBCP的开发者认为这个应该是使用者的责任,不愿意接受这种建议,具体信息请查https://issues.apache.org/jira/browse/DBCP-332
我摘录了一段“
Description
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.

I was able to fix it by overriding close method this way:

public class XBasicDataSource extends BasicDataSource {
@Override
public synchronized void close() throws SQLException {
DriverManager.deregisterDriver(DriverManager.getDriver(url));
super.close();
}
}
but I think it should be probably the default behavior of BasicDataSource. Or perhaps there should be some flag/setting on BasicDataSource, named “deregisterDriverAtClose” or so.

基本意思是数据源不会去注销jdbc,这个原因会导致内存泄漏。
到此我们明白了,tomcat不会去注销jdbc,需要我们手动去注销,重写close()方法。
后续在关闭jdbc连接的时就会去注销jdbc。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值