类 ConcurrentReferenceHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- cc.shacocloud.mirage.utils.map.ConcurrentReferenceHashMap<K,V>
-
- 所有已实现的接口:
ConcurrentMap<K,V>,Map<K,V>
public class ConcurrentReferenceHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>
一个(弱/软)引用的并发 HashMap参考 spring
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static classConcurrentReferenceHashMap.Entry<K,V>单个地图条目protected static interfaceConcurrentReferenceHashMap.Reference<K,V>对映射中包含的ConcurrentReferenceHashMap.Entry的引用。protected classConcurrentReferenceHashMap.ReferenceManager用于管理ConcurrentReferenceHashMap.Reference的策略类。static classConcurrentReferenceHashMap.ReferenceType此地图支持的各种参考类型protected static classConcurrentReferenceHashMap.Restructure可以进行的结构调整的类型。protected classConcurrentReferenceHashMap.Segment用于划分映射以允许更好的并发性能的单个段-
从类继承的嵌套类/接口 java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
构造器概要
构造器 构造器 说明 ConcurrentReferenceHashMap()创建一个新的ConcurrentReferenceHashMap实例ConcurrentReferenceHashMap(int initialCapacity)创建一个新的ConcurrentReferenceHashMap实例ConcurrentReferenceHashMap(int initialCapacity, float loadFactor)创建一个新的ConcurrentReferenceHashMap实例ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)创建一个新的ConcurrentReferenceHashMap实例ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel, ConcurrentReferenceHashMap.ReferenceType referenceType)创建一个新的ConcurrentReferenceHashMap实例ConcurrentReferenceHashMap(int initialCapacity, int concurrencyLevel)创建一个新的ConcurrentReferenceHashMap实例ConcurrentReferenceHashMap(int initialCapacity, ConcurrentReferenceHashMap.ReferenceType referenceType)创建一个新的ConcurrentReferenceHashMap实例
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 protected static intcalculateShift(int minimumValue, int maximumValue)计算可用于在指定的最大值和最小值之间创建 2 次幂值的偏移值。voidclear()booleancontainsKey(@Nullable Object key)protected ConcurrentReferenceHashMap.ReferenceManagercreateReferenceManager()返回 ConcurrentReferenceHashMap.ReferenceManager 的工厂方法。Set<Map.Entry<K,V>>entrySet()Vget(@Nullable Object key)protected intgetHash(@Nullable Object o)获取给定对象的哈希值,应用额外的哈希函数以减少冲突。protected floatgetLoadFactor()VgetOrDefault(@Nullable Object key, V defaultValue)protected @Nullable ConcurrentReferenceHashMap.Reference<K,V>getReference(@Nullable Object key, ConcurrentReferenceHashMap.Restructure restructure)protected ConcurrentReferenceHashMap.SegmentgetSegment(int index)protected intgetSegmentsSize()booleanisEmpty()voidpurgeUnreferencedEntries()删除任何已被垃圾回收且不再引用的条目。Vput(K key, V value)VputIfAbsent(K key, V value)Vremove(@Nullable Object key)booleanremove(@Nullable Object key, @Nullable Object value)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)intsize()-
从类继承的方法 java.util.AbstractMap
clone, containsValue, equals, hashCode, keySet, putAll, toString, values
-
从接口继承的方法 java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, merge, replaceAll
-
-
-
-
构造器详细资料
-
ConcurrentReferenceHashMap
public ConcurrentReferenceHashMap()
创建一个新的ConcurrentReferenceHashMap实例
-
ConcurrentReferenceHashMap
public ConcurrentReferenceHashMap(int initialCapacity)
创建一个新的ConcurrentReferenceHashMap实例- 参数:
initialCapacity- 地图的初始容量
-
ConcurrentReferenceHashMap
public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor)创建一个新的ConcurrentReferenceHashMap实例- 参数:
initialCapacity- 地图的初始容量loadFactor- 负载系数。当每个表的平均引用数超过此值时,将尝试调整大小
-
ConcurrentReferenceHashMap
public ConcurrentReferenceHashMap(int initialCapacity, int concurrencyLevel)创建一个新的ConcurrentReferenceHashMap实例- 参数:
initialCapacity- 地图的初始容量concurrencyLevel- 将同时写入映射的预期线程数
-
ConcurrentReferenceHashMap
public ConcurrentReferenceHashMap(int initialCapacity, ConcurrentReferenceHashMap.ReferenceType referenceType)创建一个新的ConcurrentReferenceHashMap实例- 参数:
initialCapacity- 地图的初始容量referenceType- 用于条目的引用类型(软或弱)
-
ConcurrentReferenceHashMap
public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)创建一个新的ConcurrentReferenceHashMap实例- 参数:
initialCapacity- 地图的初始容量loadFactor- 负载系数。当每个表的平均引用数超过此值时,将尝试调整大小concurrencyLevel- 将同时写入映射的预期线程数
-
ConcurrentReferenceHashMap
public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel, ConcurrentReferenceHashMap.ReferenceType referenceType)创建一个新的ConcurrentReferenceHashMap实例- 参数:
initialCapacity- 地图的初始容量loadFactor- 负载系数。当每个表的平均引用数超过此值时,将尝试调整大小concurrencyLevel- 将同时写入映射的预期线程数referenceType- 用于条目的引用类型(软或弱)
-
-
方法详细资料
-
getLoadFactor
protected final float getLoadFactor()
-
getSegmentsSize
protected final int getSegmentsSize()
-
getSegment
protected final ConcurrentReferenceHashMap.Segment getSegment(int index)
-
createReferenceManager
protected ConcurrentReferenceHashMap.ReferenceManager createReferenceManager()
返回 ConcurrentReferenceHashMap.ReferenceManager 的工厂方法。此方法将为每个ConcurrentReferenceHashMap.Segment调用一次。
-
getHash
protected int getHash(@Nullable @Nullable Object o)获取给定对象的哈希值,应用额外的哈希函数以减少冲突。此实现使用与 相同的 ConcurrentHashMapWang/Jenkins 算法。子类可以覆盖以提供替代哈希。 形参:- 参数:
o- 要哈希的对象(可能为空)- 返回:
- 生成的哈希代码.
-
getOrDefault
@Nullable public V getOrDefault(@Nullable @Nullable Object key, @Nullable V defaultValue)
- 指定者:
getOrDefault在接口中ConcurrentMap<K,V>- 指定者:
getOrDefault在接口中Map<K,V>
-
containsKey
public boolean containsKey(@Nullable @Nullable Object key)- 指定者:
containsKey在接口中Map<K,V>- 覆盖:
containsKey在类中AbstractMap<K,V>
-
getReference
@Nullable protected final @Nullable ConcurrentReferenceHashMap.Reference<K,V> getReference(@Nullable @Nullable Object key, ConcurrentReferenceHashMap.Restructure restructure)
- 参数:
key- 键(可以是空)restructure- 此调用期间允许的重组类型- 返回:
- 引用,如果未找到,则为
null
-
putIfAbsent
@Nullable public V putIfAbsent(@Nullable K key, @Nullable V value)
- 指定者:
putIfAbsent在接口中ConcurrentMap<K,V>- 指定者:
putIfAbsent在接口中Map<K,V>
-
purgeUnreferencedEntries
public void purgeUnreferencedEntries()
删除任何已被垃圾回收且不再引用的条目。在正常情况下,垃圾回收条目会在地图中添加或删除项目时自动清除。此方法可用于强制清除,当 Map 频繁读取但更新频率较低时非常有用。
-
calculateShift
protected static int calculateShift(int minimumValue, int maximumValue)计算可用于在指定的最大值和最小值之间创建 2 次幂值的偏移值。- 参数:
minimumValue- 最小值maximumValue- 最大值- 返回:
- 计算的偏移(使用
1 << 偏移获取值)
-
-