6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.
Summary: Fixed the race condition in the test.
Reviewed-by: jjh
--- a/jdk/test/java/lang/management/ManagementFactory/ThreadMXBeanProxy.java Fri Aug 01 13:58:29 2008 -0700
+++ b/jdk/test/java/lang/management/ManagementFactory/ThreadMXBeanProxy.java Wed Aug 06 10:24:33 2008 -0700
@@ -60,8 +60,8 @@
thread.setDaemon(true);
thread.start();
- // wait until myThread acquires mutex
- while (!mutex.isLocked()) {
+ // wait until myThread acquires mutex and lock owner is set.
+ while (!(mutex.isLocked() && mutex.getLockOwner() == thread)) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
@@ -73,17 +73,17 @@
// validate the local access
ThreadInfo[] infos = getThreadMXBean().getThreadInfo(ids, true, true);
- if (ids.length != 1) {
+ if (infos.length != 1) {
throw new RuntimeException("Returned ThreadInfo[] of length=" +
- ids.length + ". Expected to be 1.");
+ infos.length + ". Expected to be 1.");
}
thread.checkThreadInfo(infos[0]);
// validate the remote access
infos = mbean.getThreadInfo(ids, true, true);
- if (ids.length != 1) {
+ if (infos.length != 1) {
throw new RuntimeException("Returned ThreadInfo[] of length=" +
- ids.length + ". Expected to be 1.");
+ infos.length + ". Expected to be 1.");
}
thread.checkThreadInfo(infos[0]);
@@ -160,8 +160,7 @@
LockInfo[] syncs = info.getLockedSynchronizers();
if (syncs.length != OWNED_SYNCS) {
throw new RuntimeException("Number of locked syncs = " +
- syncs.length +
- " not matched. Expected: " + OWNED_SYNCS);
+ syncs.length + " not matched. Expected: " + OWNED_SYNCS);
}
AbstractOwnableSynchronizer s = mutex.getSync();
String lockName = s.getClass().getName();
@@ -174,7 +173,6 @@
throw new RuntimeException("LockInfo: " + syncs[0] +
" IdentityHashCode not matched. Expected: " + hcode);
}
-
}
}
static class Mutex implements Lock, java.io.Serializable {
@@ -214,6 +212,10 @@
s.defaultReadObject();
setState(0); // reset to unlocked state
}
+
+ protected Thread getLockOwner() {
+ return getExclusiveOwnerThread();
+ }
}
// The sync object does all the hard work. We just forward to it.
@@ -232,6 +234,8 @@
return sync.tryAcquireNanos(1, unit.toNanos(timeout));
}
+ public Thread getLockOwner() { return sync.getLockOwner(); }
+
public AbstractOwnableSynchronizer getSync() { return sync; }
}
}