本文介绍了做什么都没有而“条件”则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在浏览ForkJoinPool的Java 8版本的代码时(我从Java 7中进行了一些有趣的更改)我遇到了这个结构():
While browsing the code for the Java 8 version of ForkJoinPool(which has a few interesting changes from Java 7) I ran across this construct (here):
do {} while (!blocker.isReleasable() &&
!blocker.block());
我为什么要像这样写它而不仅仅是
I'm struggling with why you would write it like this instead of just
while (!blocker.isReleasable() &&
!blocker.block());
它只是一个语义/可读性选择,因为你可以读取第一个结构在条件
时做没事?或者我还缺少一些额外的好处吗?
Is it just a semantics/readability choice, since you could read the first construct as do "nothing" while "conditions"
? Or is there some additional benefit I'm missing?
推荐答案
如果你阅读文件顶部的评论,就在下面类声明,有一节解释了这个结构的用法:
If you read the comments at top of the file, just below the class declaration, there is a section which explains the use of this construct:
Style notes
===========
[...]
There are several occurrences of the unusual "do {} while
(!cas...)" which is the simplest way to force an update of a
CAS'ed variable. There are also other coding oddities (including
several unnecessary-looking hoisted null checks) that help
some methods perform reasonably even when interpreted (not
compiled).
这篇关于做什么都没有而“条件”则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!