提交 661a5a8b 编写于 作者: S swamyv

6732441: TEST_BUG: ThreadMXBeanProxy test fails intermittently.

Summary: Fixed the race condition in the test.
Reviewed-by: jjh
上级 68172430
...@@ -60,8 +60,8 @@ public class ThreadMXBeanProxy { ...@@ -60,8 +60,8 @@ public class ThreadMXBeanProxy {
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();
// wait until myThread acquires mutex // wait until myThread acquires mutex and lock owner is set.
while (!mutex.isLocked()) { while (!(mutex.isLocked() && mutex.getLockOwner() == thread)) {
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
...@@ -73,17 +73,17 @@ public class ThreadMXBeanProxy { ...@@ -73,17 +73,17 @@ public class ThreadMXBeanProxy {
// validate the local access // validate the local access
ThreadInfo[] infos = getThreadMXBean().getThreadInfo(ids, true, true); ThreadInfo[] infos = getThreadMXBean().getThreadInfo(ids, true, true);
if (ids.length != 1) { if (infos.length != 1) {
throw new RuntimeException("Returned ThreadInfo[] of length=" + throw new RuntimeException("Returned ThreadInfo[] of length=" +
ids.length + ". Expected to be 1."); infos.length + ". Expected to be 1.");
} }
thread.checkThreadInfo(infos[0]); thread.checkThreadInfo(infos[0]);
// validate the remote access // validate the remote access
infos = mbean.getThreadInfo(ids, true, true); infos = mbean.getThreadInfo(ids, true, true);
if (ids.length != 1) { if (infos.length != 1) {
throw new RuntimeException("Returned ThreadInfo[] of length=" + throw new RuntimeException("Returned ThreadInfo[] of length=" +
ids.length + ". Expected to be 1."); infos.length + ". Expected to be 1.");
} }
thread.checkThreadInfo(infos[0]); thread.checkThreadInfo(infos[0]);
...@@ -160,8 +160,7 @@ public class ThreadMXBeanProxy { ...@@ -160,8 +160,7 @@ public class ThreadMXBeanProxy {
LockInfo[] syncs = info.getLockedSynchronizers(); LockInfo[] syncs = info.getLockedSynchronizers();
if (syncs.length != OWNED_SYNCS) { if (syncs.length != OWNED_SYNCS) {
throw new RuntimeException("Number of locked syncs = " + throw new RuntimeException("Number of locked syncs = " +
syncs.length + syncs.length + " not matched. Expected: " + OWNED_SYNCS);
" not matched. Expected: " + OWNED_SYNCS);
} }
AbstractOwnableSynchronizer s = mutex.getSync(); AbstractOwnableSynchronizer s = mutex.getSync();
String lockName = s.getClass().getName(); String lockName = s.getClass().getName();
...@@ -174,7 +173,6 @@ public class ThreadMXBeanProxy { ...@@ -174,7 +173,6 @@ public class ThreadMXBeanProxy {
throw new RuntimeException("LockInfo: " + syncs[0] + throw new RuntimeException("LockInfo: " + syncs[0] +
" IdentityHashCode not matched. Expected: " + hcode); " IdentityHashCode not matched. Expected: " + hcode);
} }
} }
} }
static class Mutex implements Lock, java.io.Serializable { static class Mutex implements Lock, java.io.Serializable {
...@@ -214,6 +212,10 @@ public class ThreadMXBeanProxy { ...@@ -214,6 +212,10 @@ public class ThreadMXBeanProxy {
s.defaultReadObject(); s.defaultReadObject();
setState(0); // reset to unlocked state setState(0); // reset to unlocked state
} }
protected Thread getLockOwner() {
return getExclusiveOwnerThread();
}
} }
// The sync object does all the hard work. We just forward to it. // The sync object does all the hard work. We just forward to it.
...@@ -232,6 +234,8 @@ public class ThreadMXBeanProxy { ...@@ -232,6 +234,8 @@ public class ThreadMXBeanProxy {
return sync.tryAcquireNanos(1, unit.toNanos(timeout)); return sync.tryAcquireNanos(1, unit.toNanos(timeout));
} }
public Thread getLockOwner() { return sync.getLockOwner(); }
public AbstractOwnableSynchronizer getSync() { return sync; } public AbstractOwnableSynchronizer getSync() { return sync; }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册