Home >Database >Mysql Tutorial >Why Does Tomcat 7.x Issue a Memory Leak Warning When Using JDBC Data Sources?

Why Does Tomcat 7.x Issue a Memory Leak Warning When Using JDBC Data Sources?

DDD
DDDOriginal
2024-11-07 18:39:021036browse

Why Does Tomcat 7.x Issue a Memory Leak Warning When Using JDBC Data Sources?

Tomcat JDBC Data Source Warning: Memory Leak

When shutting down Tomcat 7.x with a configured Tomcat JDBC data source, you may encounter the following warning in the catalina.out log file:

Mar 26, 2013 1:17:52 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJDBC
SEVERE: The web application [/my_webapp] 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.

This warning indicates that a memory leak could occur due to the JDBC driver not being properly unregistered when the web application is stopped. To resolve this issue, despite setting the destroy-method for the DataSource, the warning persists.

Another potential cause of a memory leak is highlighted by a separate warning:

Mar 26, 2013 1:17:52 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/my_webapp] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.

To address both warnings:

  1. Move the MySQL JDBC Driver to the Tomcat lib Folder:

Move the MySQL Connector/Driver JAR file from the WAR file to the Tomcat lib folder. Deploying the WAR file with the driver included can lead to memory leaks due to improper garbage collection.

  1. Investigate the MySQL Statement Cancellation Timer Thread:

Determine why the "MySQL Statement Cancellation Timer" thread is not being stopped. Check the application code or any third-party libraries used to identify where this thread is started and ensure that it is properly stopped when the application is shut down.

By implementing these measures, you can effectively prevent memory leaks and avoid the warnings in the catalina.out log file.

The above is the detailed content of Why Does Tomcat 7.x Issue a Memory Leak Warning When Using JDBC Data Sources?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn