I would consider doing Thread.sleep(100ms) or similar to minimize time spent in this loop. Or even better, by using futures, you could do future.get(timeout, TimeOut.MILLISECONDS) to avoid having the loop at all!