Here you can find the source of waitFor(Object o, long ms, Callable
Parameter | Description |
---|---|
o | a parameter |
ms | a parameter |
c | a parameter |
Parameter | Description |
---|---|
InterruptedException | an exception |
Exception | an exception |
public static void waitFor(Object o, long ms, Callable<Boolean> c) throws InterruptedException, Exception
//package com.java2s; //License from project: Open Source License import java.util.concurrent.Callable; public class Main { /**/*from ww w .j ava 2 s . c o m*/ * Wait for async work to finish. Return when condition is true or given time has passed. * @param o * @param ms * @param c * @throws InterruptedException * @throws Exception */ public static void waitFor(Object o, long ms, Callable<Boolean> c) throws InterruptedException, Exception { synchronized (o) { final long before = System.currentTimeMillis(); final long step = ms / 10; long d = ms; while (!c.call() && (0 < d)) { o.wait(0 < step ? step : 1); d = ms - (System.currentTimeMillis() - before); } } } }