java阻塞锁_java – 阻止锁与非阻塞锁
以下是
Java Concurrency in Practice關于該主題的內容:
The JVM can implement blocking either via spin-waiting (repeatedly
trying to acquire the lock until it succeeds) or bysuspending 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 preferable 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.
而且(也就是IMO,最重要的一點):
Don’t worry excessively about the cost of uncontended synchronization. The basic mechanism is already quite fast, and JVMs can perform additional optimizations that further reduce or eliminate the cost. Instead, focus optimization efforts on areas where lock contention actually occurs.
總結
以上是生活随笔為你收集整理的java阻塞锁_java – 阻止锁与非阻塞锁的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php theexcerpt,wordp
- 下一篇: mysql 数据库设置mysql注入_M