public boolean isPortInUse(long port, int maxTries) throws Exception { log.debug("waitForPort " + port + ", entering wait loop: MAXTRIES=" + maxTries); for (int i = 0; i < maxTries; i++) { log.debug("checking port: " + port + "..."); try { if (sigar.getNetListenAddress(port) != null) { // we were able to find something return true; } } catch (SigarFileNotFoundException e) { // means port is not bound } try { Thread.sleep(2000); } catch (InterruptedException e) { // ignore } } log.debug("Num tries for port check exhausted"); return false; }