8038333: TEST_BUG: java/lang/ref/EarlyTimeout.java fails with a non-adequate message
authorigerasim
Wed, 02 Apr 2014 12:17:25 +0400
changeset 23702 95c64645aa0b
parent 23701 25ebd3b9f8b5
child 23703 8f6d9fbd6834
8038333: TEST_BUG: java/lang/ref/EarlyTimeout.java fails with a non-adequate message Reviewed-by: mchung
jdk/test/java/lang/ref/EarlyTimeout.java
--- a/jdk/test/java/lang/ref/EarlyTimeout.java	Tue Apr 01 17:25:55 2014 -0700
+++ b/jdk/test/java/lang/ref/EarlyTimeout.java	Wed Apr 02 12:17:25 2014 +0400
@@ -37,7 +37,7 @@
 /**
  * In order to demonstrate the issue we make several threads (two appears to be sufficient)
  * to block in ReferenceQueue#remove(timeout) at the same time.
- * Then, we force a reference to be enqueued by setting its referent to null and calling System.gs().
+ * Then, we force a reference to be enqueued by setting its referent to null and calling System.gc().
  * One of the threads gets the reference returned from the remove().
  * The other threads get null:
  * 1) with bug:  this may happen before the specified timeout is elapsed,
@@ -63,7 +63,10 @@
             threads[i] = new EarlyTimeout();
             threads[i].start();
         }
+        // The main thread waits until the threads has started and give it a chance
+        // for the threads to block on the queue.remove(TIMEOUT) call
         startedSignal.await();
+        Thread.sleep(TIMEOUT / 2);
         referent = null;
         System.gc();
         for (EarlyTimeout thread : threads) {
@@ -82,7 +85,7 @@
                 nonNullRefCount++;
             }
         }
-        if (nonNullRefCount != 1) {
+        if (nonNullRefCount > 1) {
             throw new RuntimeException("more than one references were removed from queue");
         }
     }