8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently
Reviewed-by: dholmes
This commit is contained in:
parent
692a92335c
commit
ea1c41f454
@ -46,18 +46,11 @@ public class ThreadBlockedCount {
|
||||
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 @@ public class ThreadBlockedCount {
|
||||
}
|
||||
|
||||
// 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 @@ public class ThreadBlockedCount {
|
||||
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 @@ public class ThreadBlockedCount {
|
||||
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 @@ public class ThreadBlockedCount {
|
||||
}
|
||||
}
|
||||
System.err.println("TEST FAILED: Blocked thread has " + count +
|
||||
" blocked counts. Expected " +
|
||||
" blocked counts. Expected at least " +
|
||||
EXPECTED_BLOCKED_COUNT);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user