code: public static boolean isLocationReachable(
        InetSocketAddress endpoint,
        Duration timeout,
        int retryCount,
        Duration retryInterval) {
      int retryLeft = retryCount;
      while (retryLeft > 0) {
        try (Socket s = new Socket()) {
          s.connect(endpoint, (int) timeout.toMillis());
          return true;
        } catch (IOException e) {
        } finally {
          SysUtils.sleep(retryInterval);
          retryLeft--;
        }
      }
      LOG.log(Level.FINE, "Failed to connect to: {0}", endpoint.toString());
      return false;
    }
docs: Tests if a network location is reachable. This is best effort and may give false
  not reachable.
  
  @param endpoint the endpoint to connect to
  @param timeout Open connection will wait for this timeout.
  @param retryCount In case of connection timeout try retryCount times.
  @param retryInterval the interval to retryCount
  @return true if the network location is reachable