Java bug with some jar packages (not updated regularly)

Source: Internet
Author: User

C3p0-0.9.5.jar Connection Pool jar package, commonly used in Web projects, when closing connection pooling, do not log off all driver

WORKAROUND: You can declare a subclass of Servletcontextlistener, override the Contextdestroyed (Servletcontextevent arg0) method and add the following code

Enumeration ds = drivermanager.getdrivers (); Try {    while  (ds.hasmoreelements ()) {        = (Driver) ds.nextelement ();        Drivermanager.deregisterdriver (d);     Catch (SQLException e) {    e.printstacktrace ();}

You can close the driver that is registered in the project run, which resolves the error that occurs when the project is closed:

The Web application [/*] registered the JBDC driver [Com.mysql.jdbc.Driver] but failed-unregister it when the Web appli Cation was stopped. To prevent a memory leak, the JDBC Driver have been forcibly unregistered.

Of course, you can also modify the source of the jar, just modify the close () method in the Com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource class, add the above code to the first line of the method ( Because this is to modify the DataSource in the Shutdown method, so do not know whether it will be triggered during the system operation, after all, SPRINGMVC is configured with the close () method, so this method does not know that will not because of repeated registration driver and the speed of the system slows down, is being tested.

Java bug with some jar packages (not updated regularly)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.