aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2015-12-29 00:22:35 +0300
committerGravatar Vitaly Takmazov2015-12-29 00:22:35 +0300
commit3a07a59e00a177d1adc179575b1ded8d763ea292 (patch)
tree3bf8efda8e83a45b4e3970cb23c1c4db586d11bc /src/main/java
parent6931eaa44ef4c67bdc1117864fc3a73c77111dea (diff)
try unregister jdbc
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/CrosspostComponent.java22
-rw-r--r--src/main/java/com/juick/PushComponent.java22
2 files changed, 44 insertions, 0 deletions
diff --git a/src/main/java/com/juick/CrosspostComponent.java b/src/main/java/com/juick/CrosspostComponent.java
index 0b5a5bc2..4e4264cb 100644
--- a/src/main/java/com/juick/CrosspostComponent.java
+++ b/src/main/java/com/juick/CrosspostComponent.java
@@ -36,8 +36,10 @@ import java.net.URL;
import java.net.URLEncoder;
import java.security.Key;
import java.sql.Connection;
+import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.util.Enumeration;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
@@ -97,6 +99,26 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
@Override
public void contextDestroyed(ServletContextEvent sce) {
+ // Now deregister JDBC drivers in this context's ClassLoader:
+ // Get the webapp's ClassLoader
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ // Loop through all drivers
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+ while (drivers.hasMoreElements()) {
+ Driver driver = drivers.nextElement();
+ if (driver.getClass().getClassLoader() == cl) {
+ // This driver was registered by the webapp's ClassLoader, so deregister it:
+ try {
+ logger.info(String.format("Deregistering JDBC driver %s", driver.toString()));
+ DriverManager.deregisterDriver(driver);
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, String.format("Error deregistering JDBC driver %s", driver), ex);
+ }
+ } else {
+ // driver was not registered by the webapp's ClassLoader and may be in use elsewhere
+ logger.log(Level.SEVERE, String.format("Not deregistering JDBC driver %s as it does not belong to this webapp's ClassLoader", driver));
+ }
+ }
executorService.shutdown();
logger.info("component destroyed");
}
diff --git a/src/main/java/com/juick/PushComponent.java b/src/main/java/com/juick/PushComponent.java
index be089928..9cc045e1 100644
--- a/src/main/java/com/juick/PushComponent.java
+++ b/src/main/java/com/juick/PushComponent.java
@@ -43,9 +43,11 @@ import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
import java.sql.Connection;
+import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
@@ -97,6 +99,26 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
@Override
public void contextDestroyed(ServletContextEvent sce) {
+ // Now deregister JDBC drivers in this context's ClassLoader:
+ // Get the webapp's ClassLoader
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ // Loop through all drivers
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+ while (drivers.hasMoreElements()) {
+ Driver driver = drivers.nextElement();
+ if (driver.getClass().getClassLoader() == cl) {
+ // This driver was registered by the webapp's ClassLoader, so deregister it:
+ try {
+ logger.info(String.format("Deregistering JDBC driver %s", driver.toString()));
+ DriverManager.deregisterDriver(driver);
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, String.format("Error deregistering JDBC driver %s", driver), ex);
+ }
+ } else {
+ // driver was not registered by the webapp's ClassLoader and may be in use elsewhere
+ logger.log(Level.SEVERE, String.format("Not deregistering JDBC driver %s as it does not belong to this webapp's ClassLoader", driver));
+ }
+ }
executorService.shutdown();
logger.info("component destroyed");
}