Doug Lea 在 J.U.C 包里面写的 BUG 又被网友发现了......

BUG描述
一个编号为 8073704 的 JDK BUG,将串联起我的这篇文章。
也就是下面的这个链接。
https://bugs.openjdk.java.net/browse/JDK-8073704
这个 BUG 在 JDK 9 版本中进行了修复。也就是说,如果你用的 JDK 8,也许会遇到这样的问题。
先带大家看看这个问题是怎么样的:










展开讨论
首先,第一个发言的哥们是 Pardeep,是在这个问题被提出的 13 天之后:









Martin 老哥提出 BUG 说 FutureTask#isDone 方法没有判断 INTERRUPING 和 COMPLETING 这个两个中间状态是不对的。 Paul 同学说,对于 INTERRUPING 这个状态,可以参照 isCancelled 方法,不需要做特殊判断。 Chris 小老弟说 Paul 同学说的对。






public static void main(String[] args) throws Exception {
AtomicReference<FutureTask<Integer>> a = new AtomicReference<>();
Runnable task = () -> {
while (true) {
FutureTask<Integer> f = new FutureTask<>(() -> 1);
a.set(f);
f.run();
}
};
Supplier<Runnable> observe = () -> () -> {
while (a.get() == null);
int c = 0;
int ic = 0;
while (true) {
c++;
FutureTask<Integer> f = a.get();
while (!f.isDone()) {}
try {
/*
Set the interrupt flag of this thread.
The future reports it is done but in some cases a call to
"get" will result in an underlying call to "awaitDone" if
the state is observed to be completing.
"awaitDone" checks if the thread is interrupted and if so
throws an InterruptedException.
*/
Thread.currentThread().interrupt();
f.get();
}
catch (ExecutionException e) {
throw new RuntimeException(e);
}
catch (InterruptedException e) {
ic ++;
System.out.println("InterruptedException observed when isDone() == true " + c + " " + ic + " " + Thread.currentThread());
}
}
};
CompletableFuture.runAsync(task);
Stream.generate(observe::get)
.limit(Runtime.getRuntime().availableProcessors() - 1)
.forEach(CompletableFuture::runAsync);
Thread.sleep(1000);
System.exit(0);
}









代码对比



虚假唤醒





Netty的一个BUG


《一个让Netty作者也感到惊讶的错误》 https://zhuanlan.zhihu.com/p/34609401
荒腔走板



更多精彩推荐
点分享 点点赞 点在看
关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 年轻干部一定要挺起脊梁冲锋在前 7924983
- 2 如台独突破红线我们将采取断然措施 7976658
- 3 普京同意停火提议 泽连斯基回应 7843078
- 4 你的民生“幸福账本” 请查收 7751846
- 5 海底捞小便门黄牛要抽20%补偿 7675469
- 6 今天数学浓度太高了 7567223
- 7 男子造谣顶流明星澳门输10亿被拘 7429486
- 8 真假鞋混卖 上海团伙获利超3000万 7364387
- 9 芯片界三巨头掌门人皆为华人 7274559
- 10 《哪吒2》烂番茄100%新鲜度 7160169