Here you can find the source of waitForService(int port)
public static boolean waitForService(int port)
//package com.java2s; /*/*from www .jav a 2 s .co m*/ * QCRI, NADEEF LICENSE * NADEEF is an extensible, generalized and easy-to-deploy data cleaning platform built at QCRI. * NADEEF means "Clean" in Arabic * * Copyright (c) 2011-2013, Qatar Foundation for Education, Science and Community Development (on * behalf of Qatar Computing Research Institute) having its principle place of business in Doha, * Qatar with the registered address P.O box 5825 Doha, Qatar (hereinafter referred to as "QCRI") * * NADEEF has patent pending nevertheless the following is granted. * NADEEF is released under the terms of the MIT License, (http://opensource.org/licenses/MIT). */ import java.io.IOException; import java.net.Socket; public class Main { 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++; } } public static boolean isPortOccupied(int port) { try (Socket ignored = new Socket("localhost", port)) { return true; } catch (IOException ignored) { return false; } } }