Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
9eb0e8e6
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9eb0e8e6
编写于
1月 14, 2014
作者:
J
jbachorik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8030847: java/lang/management/ThreadMXBean/ThreadBlockedCount.java fails intermittently again
Reviewed-by: dholmes, sla, mchung
上级
d3dcddea
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
15 deletion
+31
-15
test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java
...java/lang/management/ThreadMXBean/ThreadBlockedCount.java
+31
-15
未找到文件。
test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java
浏览文件 @
9eb0e8e6
...
...
@@ -27,7 +27,6 @@
* @summary Basic unit test of ThreadInfo.getBlockedCount()
* @author Alexei Guibadoulline and Mandy Chung
* @author Jaroslav Bachorik
*
* @run main ThreadBlockedCount
*/
...
...
@@ -35,7 +34,7 @@ import java.lang.management.*;
import
java.util.concurrent.Phaser
;
public
class
ThreadBlockedCount
{
final
static
long
EXPECTED_BLOCKED_COUNT
=
3
;
final
static
long
EXPECTED_BLOCKED_COUNT
=
3
;
final
static
int
DEPTH
=
10
;
private
static
final
ThreadMXBean
mbean
=
ManagementFactory
.
getThreadMXBean
();
...
...
@@ -48,12 +47,26 @@ public class ThreadBlockedCount {
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
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
)
{
throw
new
RuntimeException
(
"TEST FAILED."
);
}
System
.
out
.
println
(
"Test passed."
);
}
private
static
void
runTest
()
throws
Exception
{
final
Phaser
p
=
new
Phaser
(
2
);
blocking
=
new
BlockingThread
(
p
);
...
...
@@ -73,11 +86,6 @@ public class ThreadBlockedCount {
e
.
printStackTrace
(
System
.
err
);
throw
e
;
}
if
(!
testOk
)
{
throw
new
RuntimeException
(
"TEST FAILED."
);
}
System
.
out
.
println
(
"Test passed."
);
}
...
...
@@ -90,6 +98,7 @@ public class ThreadBlockedCount {
}
public
void
run
()
{
int
accumulator
=
0
;
p
.
arriveAndAwaitAdvance
();
// #1
// Enter lock a without blocking
...
...
@@ -99,7 +108,7 @@ public class ThreadBlockedCount {
// Block to enter blockedObj1
// blockedObj1 should be owned by BlockingThread
synchronized
(
blockedObj1
)
{
System
.
out
.
println
(
"BlockedThread entered lock blockedObj1."
);
accumulator
++;
// filler
}
}
...
...
@@ -111,7 +120,7 @@ public class ThreadBlockedCount {
// Block to enter blockedObj2
// blockedObj2 should be owned by BlockingThread
synchronized
(
blockedObj2
)
{
System
.
out
.
println
(
"BlockedThread entered lock blockedObj2."
);
accumulator
++;
// filler
}
}
...
...
@@ -123,11 +132,12 @@ public class ThreadBlockedCount {
// Block to enter blockedObj3
// blockedObj3 should be owned by BlockingThread
synchronized
(
blockedObj3
)
{
System
.
out
.
println
(
"BlockedThread entered lock blockedObj3."
);
accumulator
++;
// filler
}
}
// wait for the main thread to check the blocked count
println
(
"Acquired "
+
accumulator
+
" monitors"
);
p
.
arriveAndAwaitAdvance
();
// #5
// ... and we can leave now
}
// run()
...
...
@@ -165,25 +175,31 @@ public class ThreadBlockedCount {
p
.
arriveAndAwaitAdvance
();
// #1
synchronized
(
blockedObj1
)
{
System
.
out
.
println
(
"BlockingThread attempts to notify a"
);
println
(
"BlockingThread attempts to notify a"
);
waitForBlocked
();
// #2
}
// block until BlockedThread is ready
synchronized
(
blockedObj2
)
{
System
.
out
.
println
(
"BlockingThread attempts to notify b"
);
println
(
"BlockingThread attempts to notify b"
);
waitForBlocked
();
// #3
}
// block until BlockedThread is ready
synchronized
(
blockedObj3
)
{
System
.
out
.
println
(
"BlockingThread attempts to notify c"
);
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录