Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Java并发容器和框架.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### ConcurrentHashMap

HashMap线程不安全,并行put的时候有可能导致HashMap的Entry链表形成环形数据结构,next永不为空,陷入死循环
HashMap线程不安全,在jdk 1.7时,HashMap使用头插法插入链表,所以每次发生扩容的时候,进行链表复制时,都会翻转链表,所以并行put的并发生扩容的时候有可能导致HashMap的Entry链表形成环形数据结构,next永不为空,陷入死循环

```java
package com.company.concurrentclass.hashmapdeadend;
Expand Down Expand Up @@ -34,7 +34,7 @@ public class DeadEndHashMap {



ConcurrentHashMap使用了分段锁技术,一段数据配一把锁,其它段的数据不受影响。HashMap key value可以为null 但是ConcurrentHashMap不允许,直接会判处异常
ConcurrentHashMap使用了分段锁技术,一段数据配一把锁,其它段的数据不受影响(jdk1.8改为CAS锁,并引入红黑树)。HashMap key value可以为null 但是ConcurrentHashMap不允许,直接会判处异常