8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently
authorjbachorik
Tue, 21 Jan 2014 13:04:55 +0100
changeset 22353 d09e3ff5fd63
parent 22352 ecbf37860ffa
child 22354 b5f7e1bd14c9
child 22356 dc568020e87e
8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently Reviewed-by: dholmes
jdk/test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java
--- a/jdk/test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java	Tue Jan 21 10:49:49 2014 +0100
+++ b/jdk/test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java	Tue Jan 21 13:04:55 2014 +0100
@@ -46,18 +46,11 @@
     private static final Object blockedObj1 = new Object();
     private static final Object blockedObj2 = new Object();
     private static final Object blockedObj3 = new Object();
-    private static volatile boolean testOk = false;
-    private static volatile boolean verbose = false;
+    private static volatile boolean testOk = true;
     private static BlockingThread blocking;
     private static BlockedThread blocked;
 
     public static void main(String args[]) throws Exception {
-        // warmup - ensure all classes loaded and initialized etc to
-        //          avoid unintended locking and blocking in the VM
-        runTest();
-
-        testOk = true; // reset the flag
-        verbose = true;
         // real run
         runTest();
         if (!testOk) {
@@ -137,7 +130,7 @@
             }
 
             // wait for the main thread to check the blocked count
-            println("Acquired " + accumulator + " monitors");
+            System.out.println("Acquired " + accumulator + " monitors");
             p.arriveAndAwaitAdvance(); // #5
             // ... and we can leave now
         } // run()
@@ -175,31 +168,25 @@
             p.arriveAndAwaitAdvance(); // #1
 
             synchronized (blockedObj1) {
-                println("BlockingThread attempts to notify a");
+                System.out.println("BlockingThread attempts to notify a");
                 waitForBlocked(); // #2
             }
 
             // block until BlockedThread is ready
             synchronized (blockedObj2) {
-                println("BlockingThread attempts to notify b");
+                System.out.println("BlockingThread attempts to notify b");
                 waitForBlocked(); // #3
             }
 
             // block until BlockedThread is ready
             synchronized (blockedObj3) {
-                println("BlockingThread attempts to notify c");
+                System.out.println("BlockingThread attempts to notify c");
                 waitForBlocked(); // #4
             }
 
         } // run()
     } // BlockingThread
 
-    private static void println(String msg) {
-        if (verbose) {
-            System.out.println(msg);
-        }
-    }
-
     private static long getBlockedCount() {
         long count;
         // Check the mbean now
@@ -213,7 +200,7 @@
         long count = -1;
         for (int i = 0; i < 100; i++) {
             count = getBlockedCount();
-            if (count == EXPECTED_BLOCKED_COUNT) {
+            if (count >= EXPECTED_BLOCKED_COUNT) {
                 return true;
             }
             try {
@@ -225,7 +212,7 @@
             }
         }
         System.err.println("TEST FAILED: Blocked thread has " + count +
-                            " blocked counts. Expected " +
+                            " blocked counts. Expected at least " +
                             EXPECTED_BLOCKED_COUNT);
         return false;
     }