gpt4 book ai didi

java - Tomcat应用程序频繁崩溃可能是由于jdbc tomcat注册jdbc驱动程序

转载 作者:行者123 更新时间:2023-12-01 21:47:53 25 4
gpt4 key购买 nike

每次启动和停止 tomcat 服务时,我都会在 tomcat-stderr.log 文件中收到以下信息:

SEVERE: The web application [/twinkle] registered the JDBC driver [net.sourceforge.jtds.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.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#3] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:01 AM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/twinkle]

我们的应用程序在生产环境中一直崩溃,我认为这即使不是主要原因,也可能是少数几个原因之一。

在我们的应用程序中,我注意到我们在许多地方创建了新的 Thread 对象;

FTPClient.java

217  Thread.sleep(5);
443 try { Thread.sleep(5); }
catch( InterruptedException ie) {}
557 Thread.sleep(5);
576 Thread.sleep(1);

连接池.java

 private Thread m_CleanupThread = null; 
protected ConnectionPool(String urlString, String user, String passwd)
{
...
m_CleanupThread = new Thread(this);
m_CleanupThread.start();
}

还有更多像这样的 Thread 调用。

我应该使用thread.setContextClassLoader(null);

最佳答案

如果重新启动 Tomcat,那么这些内存泄漏警告将不会成为崩溃的原因。当您重新部署 Web 应用程序而不重新启动 Tomcat 时,内存泄漏警告是相关的,因为 Tomcat 将继续占用内存,而无法选择使用它或释放它(僵尸内存使用),这反过来会为您的 Web 应用程序留下更少的内存(和 Tomcat)来使用。

至于“无法找到驱动程序类”错误:仔细看看this answer并确保 Web 应用程序本身不再包含“jdbc.jar”。另外,设置appropriate options对于 c3p0(将 privilegeSpawnedThreads 设置为 true 并将 contextClassLoaderSource 设置为 library)。

您可能还想尝试删除 Tomcat 的 work directory停止 Tomcat 之后和启动 Tomcat 之前。

关于java - Tomcat应用程序频繁崩溃可能是由于jdbc tomcat注册jdbc驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35727307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com