7197919: java/lang/management/ThreadMXBean/ThreadBlockedCount.java has concurency issues
Reviewed-by: sla, mchung
This commit is contained in:
parent
b79a0fda0f
commit
d491a49652
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -32,7 +32,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.lang.management.*;
|
import java.lang.management.*;
|
||||||
import java.util.concurrent.locks.LockSupport;
|
|
||||||
|
|
||||||
public class ThreadBlockedCount {
|
public class ThreadBlockedCount {
|
||||||
final static long EXPECTED_BLOCKED_COUNT = 3;
|
final static long EXPECTED_BLOCKED_COUNT = 3;
|
||||||
@ -101,6 +100,7 @@ public class ThreadBlockedCount {
|
|||||||
System.err.println("Unexpected exception.");
|
System.err.println("Unexpected exception.");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
testFailed = true;
|
testFailed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +127,7 @@ public class ThreadBlockedCount {
|
|||||||
System.err.println("Unexpected exception.");
|
System.err.println("Unexpected exception.");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
testFailed = true;
|
testFailed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +154,7 @@ public class ThreadBlockedCount {
|
|||||||
System.err.println("Unexpected exception.");
|
System.err.println("Unexpected exception.");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
testFailed = true;
|
testFailed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,15 +168,25 @@ public class ThreadBlockedCount {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the mbean now
|
// wait for the thread stats to be updated for 10 seconds
|
||||||
ThreadInfo ti = mbean.getThreadInfo(Thread.currentThread().
|
for (int i = 0; i < 100; i++) {
|
||||||
getId());
|
if (getBlockedCount() == EXPECTED_BLOCKED_COUNT) {
|
||||||
long count = ti.getBlockedCount();
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
System.err.println("Unexpected exception.");
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
testFailed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long count = getBlockedCount();
|
||||||
if (count != EXPECTED_BLOCKED_COUNT) {
|
if (count != EXPECTED_BLOCKED_COUNT) {
|
||||||
System.err.println("TEST FAILED: Blocked thread has " + count +
|
System.err.println("TEST FAILED: Blocked thread has " + count +
|
||||||
" blocked counts. Expected " +
|
" blocked counts. Expected " +
|
||||||
EXPECTED_BLOCKED_COUNT);
|
EXPECTED_BLOCKED_COUNT);
|
||||||
testFailed = true;
|
testFailed = true;
|
||||||
}
|
}
|
||||||
} // run()
|
} // run()
|
||||||
@ -195,6 +207,7 @@ public class ThreadBlockedCount {
|
|||||||
System.err.println("Unexpected exception.");
|
System.err.println("Unexpected exception.");
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
testFailed = true;
|
testFailed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ThreadInfo info = mbean.getThreadInfo(blocked.getId());
|
ThreadInfo info = mbean.getThreadInfo(blocked.getId());
|
||||||
threadBlocked = (info.getThreadState() == Thread.State.BLOCKED);
|
threadBlocked = (info.getThreadState() == Thread.State.BLOCKED);
|
||||||
@ -233,4 +246,13 @@ public class ThreadBlockedCount {
|
|||||||
|
|
||||||
} // run()
|
} // run()
|
||||||
} // BlockedThread
|
} // BlockedThread
|
||||||
|
|
||||||
|
private static long getBlockedCount() {
|
||||||
|
long count;
|
||||||
|
// Check the mbean now
|
||||||
|
ThreadInfo ti = mbean.getThreadInfo(Thread.currentThread().
|
||||||
|
getId());
|
||||||
|
count = ti.getBlockedCount();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user