Does any JVM implement blocking with spin-waiting?(是否有任何 JVM 使用自旋等待实现阻塞?)
问题描述
在 Java 并发实践中,作者写道:
In Java Concurrency in Practice, the authors write:
当锁被争用时,失败的线程必须阻塞.JVM 可以通过 spin-waiting(反复尝试获取锁直到成功)或通过 挂起被阻塞的线程来实现阻塞要么操作系统.哪个更高效取决于上下文切换开销和直到锁可用的时间之间的关系;spin-waiting 是短等待的首选,而暂停是长等待的首选.一些 JVM 会根据过去等待时间的分析数据自适应地在两者之间进行选择,但大多数 JVM 只是挂起等待锁定的线程.
When locking is contended, the losing thread(s) must block. The JVM can implement blocking either via spin-waiting (repeatedly trying to acquire the lock until it succeeds) or by suspending the blocked thread through the operating system. Which is more efficient depends on the relationship between context switch overhead and the time until the lock becomes available; spin-waiting is preferred for short waits and suspension is preferable for long waits. Some JVMs choose between the two adaptively based on profiling data of past wait times, but most just suspend threads waiting for a lock.
当我读到这篇文章时,我感到非常惊讶.由于分析结果,是否有任何已知的 JVM 在始终旋转等待或有时旋转等待时实现阻塞?现在很难相信.
When I read this I was quite surprised. Are there any known JVMs implementing blocking either on always spin-waiting or sometimes spin-waiting due to profiling results? It's hard to believe for now.
推荐答案
这里有证据表明 JRockit 可以使用自旋锁 - http://forums.oracle.com/forums/thread.jspa?threadID=816625&tstart=494
Here is evidence that JRockit can use spinlocks - http://forums.oracle.com/forums/thread.jspa?threadID=816625&tstart=494
如果你搜索spin";在 here 列出的 JVM 选项中,您将查看在 Hotspot JVM 中使用/支持自旋锁的证据.
And if you search for "spin" in the JVM options listed here you will see evidence for the use of / support for spinlocks in Hotspot JVMs.
如果您想要一个当前示例,请查看src/hotspot/share/runtime/mutex.cpp";在 OpenJDK Java 11 源代码树中.
And if you want a current example, look at "src/hotspot/share/runtime/mutex.cpp" in the OpenJDK Java 11 source tree.
这篇关于是否有任何 JVM 使用自旋等待实现阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有任何 JVM 使用自旋等待实现阻塞?


基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01