I want to share some solutions with root cause analysis of this issue.
For Oracle Users
Solution #1
You should remove your Oracle driver from Tomcat’s /lib folder.
I was facing the same issue and it got resolved.
Note: Let the Oracle driver be in /WEB-INF/lib folder.
Solution #2
You can use real hack by sleeping thread.
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
logger.info("######### contextDestroyed #########");
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
logger.info(String.format("deregistering jdbc driver: %s", driver));
} catch (SQLException e) {
logger.info(String.format("Error deregistering driver %s", driver), e);
}
}
try { Thread.sleep(2000L); } catch (Exception e) {} // Use this thread sleep
}
Resource Link: Solution to “Tomcat can’t stop [Abandoned connection cleanup thread]”
Solution #3
Svetlin Zarev has told nothing to worry about. It is the standard message of tomcat. He has given root cause analysis like below:
This problem is occurred when an application has started
ScheduledExecutor (but this will happen with any other
Thread/TheadPool) and didn’t shut it down on contextDestroyed. So
check if you are shutting down your threads on application/server
stop.
Resource Link: Tomcat8 memory leak
Solution #4
For Oracle users, there are multiple answers in this post: To prevent a memory leak, the JDBC Driver has been forcibly unregistered
For MySQL users
Solution #5
Root Cause Analysis with Solution:
The cleanup thread for abandoned connections in the
NonRegisteringDriver class was refactored to have a static shutdown method. Memory was allocated but never released. If you
encountered this leak problem, implement the context listener in your
application with theAbandonedConnectionCleanupThread.shutdown()
call in thecontextDestroyedmethod.This issue was found in applications running under the Tomcat
application server, but it might have also applied to other
application servers.For example:
@WebListener public class YourThreadsListener implements ServletContextListener { public void contextDestroyed(ServletContextEvent arg0) { try { AbandonedConnectionCleanupThread.shutdown(); } catch (InterruptedException e) { } } ... }Note that if container does not support annotations, you add the
description to web.xml:<listener> <listener-class>user.package.YourThreadsListener</listener-class> </listener>
Resource Link: https://docs.oracle.com/cd/E17952_01/connector-j-relnotes-en/news-5-1-23.html