linux下tomcat运行一段时间后 异常停止

停止时会打印如下日志:

30-Jul-2018 13:23:56.786 INFO [Thread-8] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-10001"]
30-Jul-2018 13:23:56.839 INFO [Thread-8] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-9009"]
30-Jul-2018 13:23:56.890 INFO [Thread-8] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
2018-07-30 13:23:56,894 [localhost-startStop-2] INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Closing WebApplicationContext for namespace 'spring-servlet': startup date [Mon Jul 30 12:29:02 CST 2018]; parent: Root WebApplicationContext
2018-07-30 13:23:56,898 [localhost-startStop-2] INFO [org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler] - Shutting down ExecutorService 'qbScheduler'
2018-07-30 13:23:56,918 [localhost-startStop-2] INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Closing Root WebApplicationContext: startup date [Mon Jul 30 12:28:53 CST 2018]; root of context hierarchy
2018-07-30 13:23:56,925 [localhost-startStop-2] INFO [com.alibaba.druid.pool.DruidDataSource] - {dataSource-1} closed
30-Jul-2018 13:23:56.930 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [hours] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
30-Jul-2018 13:23:56.931 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [hours] 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.
30-Jul-2018 13:23:56.939 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [hours] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:502)
java.util.TimerThread.mainLoop(Timer.java:526)
java.util.TimerThread.run(Timer.java:505)
30-Jul-2018 13:23:56.940 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [hours] created a ThreadLocal with key of type java.lang.ThreadLocal and a value of type com.alibaba.druid.wall.spi.WallVisitorUtils.WallTopStatementContext but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

图片说明

系统是centos 7.2
tomcat是8.5版本
jdk是1.8

ssm + druid +mysql

springmvc 4.3.7.RELEASE
mybatis 3.4.2
druid 1.0.31
mysql 5.7

看报的异常信息是应用程序注册了JDBC驱动,但当程序停止时无法注销这个驱动,tomcat为了防止内存溢出,就给强制注销了。
在tomcat的server.xml文件中把

注释了就行了

虽然不会宕机,但是要从还没从根本上解决问题。

估计是定时任务的数据库连接池泄漏吧

Context是不是配置了reloadable="true", 感觉可能是内存泄漏导致的

druid.driverClassName=com.mysql.jdbc.Driver
druid.url=jdbc:mysql://localhost:3306/aliyoyo?useUnicode=true&characterEncoding=utf8&useSSL=false
druid.username=root
druid.password=123
druid.initialSize=10
druid.minIdle=6
druid.maxActive=50
druid.maxWait=60000
druid.timeBetweenEvictionRunsMillis=60000
druid.minEvictableIdleTimeMillis=300000
druid.validationQuery=SELECT 'x'
druid.testWhileIdle=true
druid.testOnBorrow=false
druid.testOnReturn=false
druid.poolPreparedStatements=false
druid.maxPoolPreparedStatementPerConnectionSize=20
druid.filters=wall,stat

业务服务使用的MySQL Connector在做数据库操作比如开启事务时,需要先做一件事情–获取数据库连接,见com.mysql.jdbc.ConnectionImpl,代码如下:,这个timer是MySQL底层的超时控制机制。为什么会有这么多的cancel timer呢?因为在业务线程里,数据库事务开启后迟迟没有flush。业务线程需要执行:开启事务->本地更新持久化对象->业务逻辑->持久化到数据库。开启事务时即获取了数据库连接,启用了CancelTimer,但因为卡业务逻辑Container这个环节,导致一直无法提交到数据库,Timer也一直不能结束。默认的spring事务是不开启超时的,

因为大量的timer线程无法释放,导致内存内存溢出,This is very likely to create a memory leak. Stack trace of thread,tomcat不挂才怪呢

我以前也碰到过这样的问题,在网上搜了一大推,搞了一天也没有解决,最后发现数据库有一条数据是 “url=“,删除这条数据就好了。
导致的原因是因为机房突然停电,再启动起来以后数据库莫名其妙的多了这条数据

我遇到这个问题后 自己的定时任务的pool-size设置为10 修改为2后无此问题 本问题结贴

我也遇到这个问题了,jdbc是警告,主要原因是因为mybatis 的Cache造成的。这个是mybatis的二级缓存,如果要是没有可以直接去掉。