提交 6f2a856f 编写于 作者: I igerasim

8038333: TEST_BUG: java/lang/ref/EarlyTimeout.java fails with a non-adequate message

Reviewed-by: mchung
上级 878b8818
...@@ -37,7 +37,7 @@ import java.util.concurrent.CountDownLatch; ...@@ -37,7 +37,7 @@ import java.util.concurrent.CountDownLatch;
/** /**
* In order to demonstrate the issue we make several threads (two appears to be sufficient) * 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. * 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(). * One of the threads gets the reference returned from the remove().
* The other threads get null: * The other threads get null:
* 1) with bug: this may happen before the specified timeout is elapsed, * 1) with bug: this may happen before the specified timeout is elapsed,
...@@ -63,7 +63,10 @@ public class EarlyTimeout extends Thread { ...@@ -63,7 +63,10 @@ public class EarlyTimeout extends Thread {
threads[i] = new EarlyTimeout(); threads[i] = new EarlyTimeout();
threads[i].start(); 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(); startedSignal.await();
Thread.sleep(TIMEOUT / 2);
referent = null; referent = null;
System.gc(); System.gc();
for (EarlyTimeout thread : threads) { for (EarlyTimeout thread : threads) {
...@@ -82,7 +85,7 @@ public class EarlyTimeout extends Thread { ...@@ -82,7 +85,7 @@ public class EarlyTimeout extends Thread {
nonNullRefCount++; nonNullRefCount++;
} }
} }
if (nonNullRefCount != 1) { if (nonNullRefCount > 1) {
throw new RuntimeException("more than one references were removed from queue"); throw new RuntimeException("more than one references were removed from queue");
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册