故障起源
今天启动tomcat8,发现网址访问不了,网页提示:
HTTP Status 404 - /zsale-web/
message /zsale-web/
description The requested resource is not available.
tomcat8
于是打开catalina.out查看日志。
26-Oct-2015 11:23:26.735 WARNING [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [zsale-web-0.0.1-SNAPSHOT] appears to have started a thread named [Abandoned connection cleanup thread] 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.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
26-Oct-2015 11:23:26.737 WARNING [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [zsale-web-0.0.1-SNAPSHOT] appears to have started a thread named [Druid-ConnectionPool-Create-2108774764] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
java.util.concurrent.locks.AbstractQueuedSynchronizer ConditionObject.await(AbstractQueuedSynchronizer.java:2039)com.alibaba.druid.pool.DruidDataSource CreateConnectionThread.run(DruidDataSource.java:1868)
tomcat7
于是换成了tomcat7再尝试一番。还是报错,报错信息大同小异。
2015-10-26 14:21:07 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/zsale-web] 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.
意思是:注册了com.mysql.jdbc.Driver以后当应用停止时无法注销,为了防止内存泄漏,jdbc驱动被强制注销。
这种错误,是由于从tomcat6.0.24版本开始,在server.xml中增加了对内存泄漏的检测。
解决方法有两种:
- 把server.xml的把这个监听去掉
- 另一个方法是换成6.0.24版本以下的tomcat(比如6.0.20)
但是我尝试把server.xml的listener去掉不行,报错依旧。
网上参考网址:
- http://liu-yuan-qing.blog.163.com/blog/static/652827872012613102323662/
- http://bbs.youkuaiyun.com/topics/390336957?page=1
- http://blog.youkuaiyun.com/a19881029/article/details/36419229
tomcat6.0.20
tomcat6.0.20
…javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
tomcat6终于不报这个错误了,但是由于servlet版本的问题报了另一个错误。
最后终于搞定,发现并不是这个错误导致网址访问不了,而是另外一个错误(连接不上数据库主机),这个错误并不是看catalina.out,而是要看localhost.2015-10-27.log:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in file [/ngbss/webapp/tomcat6/tomcat-zsale/webapps/zsale-web/WEB-INF/classes/spring/spring-context-datasource.xml]: Invocation of init method failed; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: java.net.ConnectException: Connection timed out
总结
当发现tomcat提示内存泄漏错误,有三种解决方法:
- 如果能解决掉内存泄漏最好,即使是误报也尽量修改掉
- 把tomcat的listener注释掉
- 换6.0.20以下的版本
另外需要注意的是,这种报错并不影响应用的启动,如果启动不了,那需要查找别的原因。
转载请标明出处:
本文出自:【ouyida3的博客】
2015.10.28