是否有任何JVM通过自旋等待实现阻塞? [英] Does any JVM implement blocking with spin-waiting?
问题描述
在《 Java并发实践》中,作者写道:
In Java Concurrency in Practice, the authors write:
当争用锁定时,丢失的线程必须阻塞. JVM可以通过 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.
推荐答案
Here is evidence that JRockit can use spinlocks - http://forums.oracle.com/forums/thread.jspa?threadID=816625&tstart=494
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.
这篇关于是否有任何JVM通过自旋等待实现阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!