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" ifthe state is observed to be completing."awaitDone" checks if the thread is interrupted and if sothrows 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 确保“十五五”开好局起好步 7904781
- 2 员工“踢了一脚” 救了老板一命 7809143
- 3 故宫下雪了 7712131
- 4 2026年经济工作要这么干 7616500
- 5 村支书卖小米被小米法务投诉下架 7523034
- 6 女子买千元羽绒服穿1天变吸油服 7424064
- 7 感觉时间越来越快不是错觉 7330871
- 8 不提“雪” 怎么描写雪很大 7232410
- 9 凭煮蛋涨粉350万 “蛋神”回应爆红 7141425
- 10 中央经济工作会议释放哪些重要信号 7043245










CSDN
