public static boolean waitForService(int port) { final int MAX_TRY_COUNT = 10; int tryCount = 0; while (true) { if (isPortOccupied(port)) { return true; } if (tryCount == MAX_TRY_COUNT) { System.err.println("Waiting for port " + port + " time out."); return false; } try { Thread.sleep(1000); } catch (InterruptedException e) { // ignore } tryCount++; } }
/** wait for the thread to finish */ public void join() throws InterruptedException { sucker.join(); }
public void start() { sucker = new Thread(this); sucker.start(); }