Skip to content

Commit d5df1a2

Browse files
authored
Merge pull request Snailclimb#261 from leyou240/master
Add 增加时间复杂度的描述
2 parents d114d6a + e4f41df commit d5df1a2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/java/这几道Java集合框架面试题几乎必问.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static class Segment<K,V> extends ReentrantLock implements Serializable {
250250

251251
### JDK1.8 (上面有示意图)
252252

253-
ConcurrentHashMap取消了Segment分段锁,采用CAS和synchronized来保证并发安全。数据结构跟HashMap1.8的结构类似,数组+链表/红黑二叉树。
253+
ConcurrentHashMap取消了Segment分段锁,采用CAS和synchronized来保证并发安全。数据结构跟HashMap1.8的结构类似,数组+链表/红黑二叉树。Java 8在链表长度超过一定阈值(8)时将链表(寻址时间复杂度为O(N))转换为红黑树(寻址时间复杂度为O(long(N)))
254254

255255
synchronized只锁定当前链表或红黑二叉树的首节点,这样只要hash不冲突,就不会产生并发,效率又提升N倍。
256256

0 commit comments

Comments
 (0)