code: public static void detectDeadConnections() {
          if (CONNECTION_DETECTOR_RUNNING) {
              return;
          }
          final Logger log = LoggerFactory.getLogger(ConnectionManager.class);
          Thread deadConnThread = new Thread(new Runnable() {
              public void run() {
                  CONNECTION_DETECTOR_RUNNING = true;
                  try {
                      log.debug("Starting dead connection detection thread");
                      while (detectDeadConnection) {
                          log.debug("Checking if there are any dead connections");
                          long now = DateTime.now().getMillis();
                          for (DataSiftConnection data : connections) {
                              if (data.lastSeen() != null) {
                                  if (now - data.lastSeen().getMillis() >=
                                          TimeUnit.SECONDS.toMillis(CONNECTION_TIMEOUT_LIMIT)) {
                                      log.info("Dead connection found, triggering re-connection");
                                      data.closeAndReconnect();
                                  }
                              }
                          }
                          log.debug(String.format("Checked %s connections", connections.size()));
                          try {
                              Thread.sleep(TimeUnit.SECONDS.toMillis(CONNECTION_TIMEOUT));
                          } catch (InterruptedException e) {
                              LoggerFactory.getLogger(getClass()).info("Interrupted while waiting to check conn");
                          }
                      }
                  } finally {
                      CONNECTION_DETECTOR_RUNNING = false;
                  }
              }
          }, "dead-connections-monitor");
          deadConnThread.setDaemon(true);
          deadConnThread.start();
      }
docs: /*
  Starts a thread which checks periodically for dead connections and force them to re-connect.
  IF AND ONLY IF a thread isn't already running to do this