1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Merge pull request #261 from leyou240/master

Add  增加时间复杂度的描述
This commit is contained in:
SnailClimb 2019-04-09 08:57:18 -05:00 committed by GitHub
commit d5df1a2987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -250,7 +250,7 @@ static class Segment<K,V> extends ReentrantLock implements Serializable {
### JDK1.8 (上面有示意图)
ConcurrentHashMap取消了Segment分段锁采用CAS和synchronized来保证并发安全。数据结构跟HashMap1.8的结构类似,数组+链表/红黑二叉树。
ConcurrentHashMap取消了Segment分段锁采用CAS和synchronized来保证并发安全。数据结构跟HashMap1.8的结构类似,数组+链表/红黑二叉树。Java 8在链表长度超过一定阈值8时将链表寻址时间复杂度为O(N)转换为红黑树寻址时间复杂度为O(long(N))
synchronized只锁定当前链表或红黑二叉树的首节点这样只要hash不冲突就不会产生并发效率又提升N倍。