开发者

MySQL create memory leak in Tomcat

开发者 https://www.devze.com 2023-01-01 20:26 出处:网络
I have set a JDBCRealm for web-app inside tomcat, and when I reload it I got this from tomcat: SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it

I have set a JDBCRealm for web-app inside tomcat, and when I reload it I got this from tomcat:

SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped开发者_如何学JAVA. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

I use tomcat 6.0.24, with MySQL Connector 5.1.10,,,

Is there a way to clean it up, so tomcat won't display SEVERE message?


This is not a leak, or at least it is one that does not matter. If you have a singleton object (The JDBC driver) and it is never released until the app finishes, does it matter ?
The database will close any pending connections after a given amount of time.

If it really bothers you, you could fix it by overriding close method this way:

public class XBasicDataSource extends BasicDataSource {
    @Override
    public synchronized void close() throws SQLException {
        DriverManager.deregisterDriver(DriverManager.getDriver(url));
        super.close();
    }
}

And use your XBasicDataSource .

0

精彩评论

暂无评论...
验证码 换一张
取 消