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 使用自旋等待实现阻塞?


- 如何指定 CORS 的响应标头? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 获取数字的最后一位 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01