# HG changeset patch # User jbachorik # Date 1390292243 -3600 # Node ID 4143cdafa0d5d00c7ee702af1c2549624b616313 # Parent 2aa385c1c4d8b86ccaaf60a115698324e72a7b6d 8031559: javax/management/monitor/StartStopTest.java fails intermittently Reviewed-by: dfuchs, sla diff -r 2aa385c1c4d8 -r 4143cdafa0d5 jdk/test/javax/management/monitor/StartStopTest.java --- a/jdk/test/javax/management/monitor/StartStopTest.java Tue Jan 21 09:15:46 2014 +0100 +++ b/jdk/test/javax/management/monitor/StartStopTest.java Tue Jan 21 09:17:23 2014 +0100 @@ -27,6 +27,8 @@ * @summary Test that tasks are cancelled properly when * monitors are started and stopped in a loop. * @author Luis-Miguel Alventosa + * @library /lib/testlibrary + * @run build jdk.testlibrary.Utils * @run clean StartStopTest * @run build StartStopTest * @run main/othervm/timeout=300 StartStopTest 1 @@ -52,14 +54,15 @@ import javax.management.monitor.MonitorNotification; import javax.management.monitor.StringMonitor; +import jdk.testlibrary.Utils; + public class StartStopTest { - static int maxPoolSize; static final AtomicInteger counter = new AtomicInteger(); // MBean class public class ObservedObject implements ObservedObjectMBean { - public boolean called = false; + volatile public boolean called = false; public Integer getInteger() { task("Integer"); return 0; @@ -142,7 +145,7 @@ for (int i = 0; i < nTasks; i++) monitor[i].start(); echo(">>> MONITORS started"); - Thread.sleep(500); + doSleep(500); echo(">>> Check FLAGS true"); for (int i = 0; i < nTasks; i++) if (!monitored[i].called) { @@ -154,7 +157,7 @@ for (int i = 0; i < nTasks; i++) monitor[i].stop(); echo(">>> MONITORS stopped"); - Thread.sleep(500); + doSleep(500); echo(">>> Set FLAGS to false"); for (int i = 0; i < nTasks; i++) monitored[i].called = false; @@ -208,4 +211,8 @@ echo(">>> Happy Bye, Bye!"); } } + + private static void doSleep(long ms) throws Exception { + Thread.sleep(Math.round(ms * Utils.TIMEOUT_FACTOR)); + } }