Here you can find the source of executeUntilNonNullOrTimeout(final long timeoutMs, final long timeBetweenPollsMs, final Callable
public static <V> V executeUntilNonNullOrTimeout(final long timeoutMs, final long timeBetweenPollsMs, final Callable<V> callable) throws InterruptedException
//package com.java2s; //License from project: Open Source License import java.util.Date; import java.util.concurrent.Callable; public class Main { public static <V> V executeUntilNonNullOrTimeout(final long timeoutMs, final long timeBetweenPollsMs, final Callable<V> callable) throws InterruptedException { final long started = new Date().getTime(); long elapsedTime = 0; while (elapsedTime < timeoutMs) { final V value; try { value = callable.call(); } catch (Exception e) { throw new RuntimeException(e); }//from www . j a v a 2 s . c om if (value != null) { return value; } else { elapsedTime = (new Date().getTime()) - started; } Thread.sleep(timeBetweenPollsMs); } return null; } }