Java中的锁机制
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java中的锁机制相关的知识,希望对你有一定的参考价值。
Java中的锁机制:
- API层面:Synchronized,AQS(CLH): ReentrantLock,ReentrantReadWriteLock,StampedLock(Ordered RW locks)
- JVM层面(Hotspot): SpinLock,Biased,Stack-Locked(轻量级锁), Inflated(重量级锁)
- Neutral: Unlocked
- Biased: Locked/Unlocked + Unshared
- Stack-Locked: Locked + Shared but uncontended,The mark points to displaced mark word on the owner thread‘s stack.
- Inflated: Locked/Unlocked + Shared and contended,Threads are blocked in monitorenter or wait().,The mark points to heavy-weight "objectmonitor" structure.
参考:
http://openjdk.java.net/groups/hotspot/docs/RuntimeOverview.html
AbstractQueuedLongSynchronizer,StampedLock源码
http://cs.rochester.edu/research/synchronization/pseudocode/ss.html
以上是关于Java中的锁机制的主要内容,如果未能解决你的问题,请参考以下文章