azkaban-aplcache

Remove the DB monitoring thread (#974) Since the datasource

4/10/2017 12:39:03 PM

Details

diff --git a/azkaban-common/src/main/java/azkaban/database/DataSourceUtils.java b/azkaban-common/src/main/java/azkaban/database/DataSourceUtils.java
index 4e33d45..b884c71 100644
--- a/azkaban-common/src/main/java/azkaban/database/DataSourceUtils.java
+++ b/azkaban-common/src/main/java/azkaban/database/DataSourceUtils.java
@@ -124,8 +124,6 @@ public class DataSourceUtils {
    */
   public static class MySQLBasicDataSource extends AzkabanDataSource {
 
-    private static MonitorThread monitorThread = null;
-
     private final String url;
 
     private MySQLBasicDataSource(String host, int port, String dbName,
@@ -142,11 +140,6 @@ public class DataSourceUtils {
       setMaxActive(numConnections);
       setValidationQuery("/* ping */ select 1");
       setTestOnBorrow(true);
-
-      if (monitorThread == null) {
-        monitorThread = new MonitorThread(this);
-        monitorThread.start();
-      }
     }
 
     @Override
@@ -158,51 +151,6 @@ public class DataSourceUtils {
     public String getDBType() {
       return "mysql";
     }
-
-    private class MonitorThread extends Thread {
-      private static final long MONITOR_THREAD_WAIT_INTERVAL_MS = 30 * 1000;
-      private boolean shutdown = false;
-      MySQLBasicDataSource dataSource;
-
-      public MonitorThread(MySQLBasicDataSource mysqlSource) {
-        this.setName("MySQL-DB-Monitor-Thread");
-        setDaemon(true);
-        dataSource = mysqlSource;
-      }
-
-      @SuppressWarnings("unused")
-      public void shutdown() {
-        shutdown = true;
-        this.interrupt();
-      }
-
-      public void run() {
-        while (!shutdown) {
-          synchronized (this) {
-            try {
-              pingDB();
-              wait(MONITOR_THREAD_WAIT_INTERVAL_MS);
-            } catch (InterruptedException e) {
-              logger.info("Interrupted. Probably to shut down.");
-            }
-          }
-        }
-      }
-
-      private void pingDB() {
-        Connection connection = null;
-        try {
-          connection = dataSource.getConnection();
-          PreparedStatement query = connection.prepareStatement("SELECT 1");
-          query.execute();
-        } catch (SQLException e) {
-          logger.error("Unable to reach MySQL server on " + url);
-        } finally {
-          DbUtils.closeQuietly(connection);
-        }
-      }
-    }
-
   }
 
   /**