Web 应用程序 [] 似乎启动了一个名为 [Abandoned connection cleanup thread] com.mysql.jdbc.AbandonedConnectionCleanupThread 的线程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25699985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:01:25  来源:igfitidea点击:

The web application [] appears to have started a thread named [Abandoned connection cleanup thread] com.mysql.jdbc.AbandonedConnectionCleanupThread

mysqlspringjdbcmemory-leaks

提问by Jeff

In the middle of my web-development I just close my web-app in my eclipse IDE, about a minute, I just saw a WARNINGin my eclipse console.

在我的 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
    ...]

It did not caused any memory leak so far, I checked my VisualVM, everything is working as usual, but as I search more about this thing I realize that this warning is caused by the MySQL driver not releasing resources or not being closed properly(I dont know how to say it exactly) and I ended up in this post at SO related issue

到目前为止,它没有导致任何内存泄漏,我检查了我的 VisualVM,一切正常,但是当我搜索更多关于这件事的时候,我意识到这个警告是由 MySQL 驱动程序没有释放资源或没有正确关闭引起的(我不知道如何确切地说),我最终在 SO相关问题的这篇文章中

and the OP is right the answer of "don't worry about it" won't be sufficient. This warning bothers me because it may give me some future persistence problemsand that worries me a lot, I tried the code the OP has written but I'm having a problem what Librariesshould I use to make this code work. This is what I got sor far..

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();
    }
  }
}

I just want to know what Libraries do I need or If I'm using the right libraries to implement this properly, I do not even know what Logger should I use, thank you for any help,

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

回答by borjab

See this answer. It seems that MySQL driver should be in {$TOMCAT]/libshared between applications. Check that you are not including it with each application. At least it worked for me and I have been able to remove the warning.

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

If you are using Maven mark the dependency as provided.

如果您使用 Maven,请将依赖项标记为提供。


UPDATE:
root cause is that Tomcat have problems to garbage collect the driver because it is registered in a singleton common to several applications. Closing one application does not allow Tomcat to release the driver. See this answer.


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

回答by Kanhaiya Kumar

This works for me.

这对我有用

Issue was with elastic search in my case.

就我而言,问题在于弹性搜索。

Send a DELETErequest from postman to below endpoint and restart your application .

从邮递员向以下端点发送DELETE请求并重新启动您的应用程序。

http://localhost:9200/*