ConcurrentHashMap
1. 构造器
ConcurrentHashMap的构造器和HashMap的构造器基本相同
2. put方法
ConcurrentHashMap键或者值为空会抛出空指针异常,put方法开始先求取hash
final V putVal(K key, V value, boolean onlyIfAbsent) {
if (key == null || value == null) throw new NullPointerException();
int hash = spread(key.hashCode());
...
}
static final int spread(int h) {
return (h ^ (h >>> 16)) & HASH_BITS;
}
大约 8 分钟