diff --git a/activemq-core/src/test/java/org/apache/activemq/util/Wait.java b/activemq-core/src/test/java/org/apache/activemq/util/Wait.java index 7756d5e830..12b7ede333 100644 --- a/activemq-core/src/test/java/org/apache/activemq/util/Wait.java +++ b/activemq-core/src/test/java/org/apache/activemq/util/Wait.java @@ -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; @@ -29,12 +32,17 @@ public class Wait { public static boolean waitFor(Condition condition) throws Exception { return waitFor(condition, MAX_WAIT_MILLIS); } - + 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;