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 使用自旋等待实现阻塞?
基础教程推荐
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01