是否有任何 JVM 使用自旋等待实现阻塞?

Does any JVM implement blocking with spin-waiting?(是否有任何 JVM 使用自旋等待实现阻塞?)
本文介绍了是否有任何 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 使用自旋等待实现阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to implement RecyclerView with section header depending on category?(如何根据类别实现带有节标题的 RecyclerView?)
How to generate JNI header file in Eclipse(如何在 Eclipse 中生成 JNI 头文件)
Setting a custom HTTP header dynamically with Spring-WS client(使用 Spring-WS 客户端动态设置自定义 HTTP 标头)
Could you technically call the string[] anything in the main method?(从技术上讲,您可以在 main 方法中调用 string[] 吗?)
What is the proper way of setting headers in a URLConnection?(在 URLConnection 中设置标头的正确方法是什么?)
How to overwrite http-header quot;Hostquot; in a HttpURLConnection?(如何覆盖 http-header “主机在 HttpURLConnection 中?)