mirror of https://github.com/apache/activemq.git
allow the sleep time to be specified to allow finer grain return from a wait
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1363314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eebe1358d2
commit
f135b7ab76
|
@ -18,9 +18,12 @@
|
|||
package org.apache.activemq.util;
|
||||
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Wait {
|
||||
|
||||
public static final long MAX_WAIT_MILLIS = 30*1000;
|
||||
public static final int SLEEP_MILLIS = 1000;
|
||||
|
||||
public interface Condition {
|
||||
boolean isSatisified() throws Exception;
|
||||
|
@ -31,10 +34,15 @@ public class Wait {
|
|||
}
|
||||
|
||||
public static boolean waitFor(final Condition condition, final long duration) throws Exception {
|
||||
return waitFor(condition, MAX_WAIT_MILLIS, SLEEP_MILLIS);
|
||||
}
|
||||
|
||||
public static boolean waitFor(final Condition condition, final long duration, final int sleepMillis) throws Exception {
|
||||
|
||||
final long expiry = System.currentTimeMillis() + duration;
|
||||
boolean conditionSatisified = condition.isSatisified();
|
||||
while (!conditionSatisified && System.currentTimeMillis() < expiry) {
|
||||
Thread.sleep(1000);
|
||||
TimeUnit.MILLISECONDS.sleep(sleepMillis);
|
||||
conditionSatisified = condition.isSatisified();
|
||||
}
|
||||
return conditionSatisified;
|
||||
|
|
Loading…
Reference in New Issue