Java中的鎖機制

Java中的鎖機制:

  1. API層面:Synchronized,AQS(CLH): ReentrantLock,ReentrantReadWriteLock,StampedLock(Ordered RW locks)
  2. 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章