加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Thread.yield()仍然是一个跨平台的雷区?

发布时间:2020-12-15 04:35:40 所属栏目:Java 来源:网络整理
导读:我可以找到 old references和SO的答案,说Thread.yield()的行为因平台而异. This answer表示这是因为实际上没有指定行为. 对于现代版本的Java,Thread.yield()行为是否因平台而异? 编辑 我已经阅读了文档.我理解它意味着什么.我在询问实际行为. 解决方法 从Ja
我可以找到 old references和SO的答案,说Thread.yield()的行为因平台而异. This answer表示这是因为实际上没有指定行为.

对于现代版本的Java,Thread.yield()行为是否因平台而异?

编辑

我已经阅读了文档.我理解它意味着什么.我在询问实际行为.

解决方法

从Java 8 API(最新的非测试版到目前为止):

A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint.

Yield is a heuristic attempt to improve relative progression between
threads that would otherwise over-utilise a CPU. Its use should be
combined with detailed profiling and benchmarking to ensure that it
actually has the desired effect.

It is rarely appropriate to use this method. It may be useful for
debugging or testing purposes,where it may help to reproduce bugs due
to race conditions. It may also be useful when designing concurrency
control constructs such as the ones in the java.util.concurrent.locks
package.

其含义是:

>是的,仍然依赖于平台>是的,启发式

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读