I need to close all tomcat connection pool's datasource connections while context destroyed. Is DriverManager.deregisterDriver(driver) closes all connections?
Enumeration<Driver> enumDrivers = DriverManager.getDrivers();
while (enumDrivers.hasMoreElements()) {
Driver driver = enumDrivers.nextElement();
DriverManager.deregisterDriver(driver);
}
Here is the code of
DriverManager.deregisterDriver(Driver driver)on JDK 8:Note that it just removes the
DriverInfoinstance from a list (registeredDrivers). In case it finds aDriverActionassociated with the driver, it callsdriverAction.deregister(). From the docs of the method:So in all cases, you shouldn't count on this, unless you're absolutely sure of the underlying implementation. But this would render your application too coupled with it.