protected synchronized void testAndCreateConnection() {
    if (conn != null) {
      // This method is reached when error occurs while sending msg, so the session must be bad
      session.remove();
      if (!isConnectionHealthy()) {
        // I am the first thread to detect the error, cleanup old connection & reconnect
        try {
          conn.close();
        } catch (Exception e) {
          LOG.error("Unable to close bad JMS connection, ignored error", e);
        }
        conn = createConnection();
      }
    } else {
      conn = createConnection();
    }
    try {
      session.set(createSession());
    } catch (JMSException e) {
      LOG.error("Couldn't create JMS session, ignored the error", e);
    }
  }
Does a health check on the connection by sending a dummy message.
Create the connection if the connection is found to be bad
Also recreates the session
hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/NotificationListener.java