java – 是否有任何JVM通过自旋等待实现阻塞?

Java Concurrency in Practice中,作者写道:

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通过自旋等待或有时由于分析结果而实现阻塞?现在很难相信.

解决方法:

以下证据表明JRockit可以使用自旋锁 – http://forums.oracle.com/forums/thread.jspa?threadID=816625&tstart=494

如果您在here列出的JVM选项中搜索“spin”,您将看到在Hotspot JVM中使用/支持自旋锁的证据.

上一篇:linux – 替代EDF算法


下一篇:springboot中使用自定义线程池ThreadPoolTaskExecutor