在Java中偏置锁定 [英] Biased locking in java

查看:294
本文介绍了在Java中偏置锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继续阅读关于如何偏置锁定,使用标志-XX:+ UseBiasedLocking,可以提高无争用同步的性能。我找不到它的作用,它如何提高性能的参考。

I keep reading about how biased locking, using the flag -XX:+UseBiasedLocking, can improve the performance of uncontended synchronization. I couldnt find a reference to what it does and how it improves the performance.

任何人都可以解释我究竟是什么,或者可能指向我解释一些链接/资源

Can anyone explain me what exactly it is or may be point me to some links/resources that explains??

推荐答案

基本上,如果你的对象只被一个线程锁定,VM可以做一个优化和偏向那个对象到该线程,使得对对象的后续原子操作不产生同步成本。我想这通常面向过于保守的代码,对对象执行锁定,而不会将它们暴露给另一个线程。实际的同步开销只会在另一个线程尝试获取对象上的锁时才开始。

Essentially, if your objects are locked only by one thread, the VM can make an optimization and "bias" that object to that thread in such a way that subsequent atomic operations on the object incurs no synchronization cost. I suppose this is typically geared towards overly conservative code that performs locks on objects without ever exposing them to another thread. The actual synchronization overhead will only kick in once another thread tries to obtain a lock on the object.

它在Java 6中默认是开启的。

It is on by default in Java 6.


-XX:+ UseBiasedLocking
启用一种用于提高无争用同步性能的技术。对象被偏向线程,线程首先通过监听器字节码或同步方法调用获取其监视器;由该线程执行的后续监视器相关操作在多处理器机器上相对快得多。具有大量无争用同步的一些应用可以在启用该标志的情况下获得显着的加速;具有某些锁定模式的一些应用可能看到减速,尽管已经尝试将负面影响最小化。

-XX:+UseBiasedLocking Enables a technique for improving the performance of uncontended synchronization. An object is "biased" toward the thread which first acquires its monitor via a monitorenter bytecode or synchronized method invocation; subsequent monitor-related operations performed by that thread are relatively much faster on multiprocessor machines. Some applications with significant amounts of uncontended synchronization may attain significant speedups with this flag enabled; some applications with certain patterns of locking may see slowdowns, though attempts have been made to minimize the negative impact.

这篇关于在Java中偏置锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆