[localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The

[localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [XXX] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it.

项目环境:tomcat8.5+ssm 在关闭web项目时发生一下警告:

 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [XXX] 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:144)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41)
28-Jan-2019 10:55:56.095 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
28-Jan-2019 10:55:56.096 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
28-Jan-2019 10:55:56.109 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
28-Jan-2019 10:55:56.110 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]

根据StackOverFlow网站的内容找到了以下回答:

在我的web开发过程中,我只是在我的eclipse
IDE中关闭我的web应用程序,大约一分钟,我刚刚在我的eclipse控制台中看到了一个警告。

WARNING: The web application [/Spring.MVC] 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. Sep 06, 2014 8:31:55 PM
org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
WARNING: The web application [/Spring.MVC] 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(Unknown Source)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
Sep 06, 2014 8:32:00 PM org.apache.catalina.core.ApplicationContext
log INFO: No Spring WebApplicationInitializer types detected on
classpath SLF4J: Failed to load class
“org.slf4j.impl.StaticLoggerBinder”. SLF4J: Defaulting to no-operation
(NOP) logger implementation SLF4J: See
http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details. Sep 06, 2014 8:32:00 PM
org.apache.catalina.core.ApplicationContext log INFO: Initializing
Spring root WebApplicationContext Sep 06, 2014 8:32:03 PM
org.hibernate.jpa.internal.util.LogHelper
logPersistenceUnitInformation INFO: HHH000204: Processing
PersistenceUnitInfo [
name: personPU
…] 到目前为止它没有造成任何内存泄漏,我检查了我的VisualVM,一切正常,但是当我搜索更多关于这件事情时,我发现这个警告是由MySQL驱动程序没有释放资源或没有正确关闭引起的(我不知道该怎么说呢?我最后在SO
相关问题上发表了这篇文章

并且OP是正确
的,“不要担心它”的答案是不够的。这个警告困扰我,因为它可能会给我一些未来的持久性问题,这让我很担心,我尝试了OP编写的代码,但是我遇到了一个问题,我应该使用哪些库来使代码工作。这是我得到的东西…

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.hibernate.annotations.common.util.impl.LoggerFactory;
import com.mysql.jdbc.AbandonedConnectionCleanupThread;
@WebListener
public class ContextFinalizer implements ServletContextListener {

private static final Logger LOGGER = LoggerFactory.getLogger(ContextFinalizer.class);

public void contextInitialized(ServletContextEvent sce) {
}

public void contextDestroyed(ServletContextEvent sce) {
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    Driver d = null;
    while (drivers.hasMoreElements()) {
        try {
            d = drivers.nextElement();
            DriverManager.deregisterDriver(d);
            LOGGER.warn(String.format("Driver %s deregistered", d));
        }
        catch (SQLException ex) {
            LOGGER.warn(String.format("Error deregistering driver %s", d), ex);
        }
    }
    try {
        AbandonedConnectionCleanupThread.shutdown();
    }
    catch (InterruptedException e) {
        logger.warn("SEVERE problem cleaning up: " + e.getMessage());
        e.printStackTrace();
    }
  }
}

我只是想知道我需要哪些库,或者如果我正确使用正确的库来实现这一点,我甚至不知道我应该使用什么Logger,谢谢你的帮助,

得到23个赞的回答:

看到这个答案。似乎MySQL驱动程序应该{$TOMCAT]/lib在应用程序之间共享。检查每个应用程序是否包含它。至少它对我有用,我已经能够删除警告。

如果您使用Maven标记所提供的依赖项。


更新:
根本原因是Tomcat在垃圾收集驱动程序时遇到问题,因为它在多个应用程序的公共单件中注册。关闭一个应用程序不允许Tomcat释放驱动程序。看到这个答案。

解决:

将pom.xml中的mysql驱动依赖去掉(前提是要你的tomcat 中的lib目录中有这个jar包)

12-Jul-2023 18:36:28.896 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file 12-Jul-2023 18:36:28.898 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/setting] startup failed due to previous errors 2023-07-12 18:36:28,899 [// - - ] INFO org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Wed Jul 12 18:36:27 CST 2023]; root of context hierarchy 2023-07-12 18:36:28,900 [// - - ] INFO org.springframework.cache.ehcache.EhCacheManagerFactoryBean - Shutting down EhCache CacheManager 12-Jul-2023 18:36:28.908 WARNING [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [setting] 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. 12-Jul-2023 18:36:28.908 WARNING [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [setting] 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:143) com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
最新发布
07-13
09-Jun-2023 15:19:12.806 信息 [main] org.apache.catalina.core.StandardServer.await 通过关闭端口接收到有效的关闭命令。正在停止服务器实例。 09-Jun-2023 15:19:12.807 信息 [main] org.apache.coyote.AbstractProtocol.pause 暂停ProtocolHandler["http-nio-8080"] 09-Jun-2023 15:19:13.217 信息 [main] org.apache.catalina.core.StandardService.stopInternal 正在停止服务[Catalina] 09-Jun-2023 15:19:13.230 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc Web应用程序 [ROOT] 注册了JDBC驱动程序 [com.mysql.cj.jdbc.Driver],但在Web应用程序停止时无法注销它。 为防止内存泄漏,JDBC驱动程序已被强制取消注册。 09-Jun-2023 15:19:13.230 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc Web应用程序 [ROOT] 注册了JDBC驱动程序 [org.apache.ibatis.datasource.unpooled.UnpooledDataSource.DriverProxy],但在Web应用程序停止时无法注销它。 为防止内存泄漏,JDBC驱动程序已被强制取消注册。 09-Jun-2023 15:19:13.230 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads Web应用程序[ROOT]似乎启动了一个名为[mysql-cj-abandoned-connection-cleanup]的线程,但未能停止它。这很可能会造成内存泄漏。线程的堆栈跟踪:[ java.lang.Object.wait(Native Method) java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144) com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:91) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) java.lang.Thread.run(Thread.java:750)] 09-Jun-2023 15:19:13.241 信息 [main] org.apache.coyote.AbstractProtocol.stop 正在停止ProtocolHandler ["http-nio-8080"] 09-Jun-2023 15:19:13.252 信息 [main] org.apache.coyote.AbstractProtocol.destroy 正在摧毁协议处理器 ["http-nio-8080"] 是什么原因
06-10
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值