摘要:序本文主要研究一下的继承了接口,并指定类型为实现了接口,它内部使用实现提供了及两个静态方法用于创建其中方法创建为,为,为的小结继承了接口,并指定类型为实现了接口,它内部使用实现提供了及两个静态方法用于创建其中方法创建为,为,为的
序
本文主要研究一下Elasticsearch的ConcurrentMapLong
ConcurrentMapLongelasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentMapLong.java
public interface ConcurrentMapLongextends ConcurrentMap { T get(long key); T remove(long key); T put(long key, T value); T putIfAbsent(long key, T value); }
ConcurrentMapLong继承了ConcurrentMap接口,并指定key类型为Long
ConcurrentHashMapLongelasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentHashMapLong.java
public class ConcurrentHashMapLongimplements ConcurrentMapLong { private final ConcurrentMap map; public ConcurrentHashMapLong(ConcurrentMap map) { this.map = map; } @Override public T get(long key) { return map.get(key); } @Override public T remove(long key) { return map.remove(key); } @Override public T put(long key, T value) { return map.put(key, value); } @Override public T putIfAbsent(long key, T value) { return map.putIfAbsent(key, value); } // MAP DELEGATION @Override public boolean isEmpty() { return map.isEmpty(); } @Override public int size() { return map.size(); } @Override public T get(Object key) { return map.get(key); } @Override public boolean containsKey(Object key) { return map.containsKey(key); } @Override public boolean containsValue(Object value) { return map.containsValue(value); } @Override public T put(Long key, T value) { return map.put(key, value); } @Override public T putIfAbsent(Long key, T value) { return map.putIfAbsent(key, value); } @Override public void putAll(Map extends Long, ? extends T> m) { map.putAll(m); } @Override public T remove(Object key) { return map.remove(key); } @Override public boolean remove(Object key, Object value) { return map.remove(key, value); } @Override public boolean replace(Long key, T oldValue, T newValue) { return map.replace(key, oldValue, newValue); } @Override public T replace(Long key, T value) { return map.replace(key, value); } @Override public void clear() { map.clear(); } @Override public Set keySet() { return map.keySet(); } @Override public Collection values() { return map.values(); } @Override public Set > entrySet() { return map.entrySet(); } @Override public boolean equals(Object o) { return map.equals(o); } @Override public int hashCode() { return map.hashCode(); } @Override public String toString() { return map.toString(); } }
ConcurrentHashMapLong实现了ConcurrentMapLong接口,它内部使用ConcurrentMap实现
ConcurrentCollectionselasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java
public abstract class ConcurrentCollections { static final int aggressiveConcurrencyLevel; static { aggressiveConcurrencyLevel = Math.max(Runtime.getRuntime().availableProcessors() * 2, 16); } //...... public staticConcurrentMap newConcurrentMap() { return new ConcurrentHashMap<>(); } public static ConcurrentMapLong newConcurrentMapLong() { return new ConcurrentHashMapLong<>(ConcurrentCollections. newConcurrentMap()); } public static ConcurrentMapLong newConcurrentMapLongWithAggressiveConcurrency() { return new ConcurrentHashMapLong<>(ConcurrentCollections. newConcurrentMapWithAggressiveConcurrency()); } public static ConcurrentMap newConcurrentMapWithAggressiveConcurrency() { return newConcurrentMapWithAggressiveConcurrency(16); } public static ConcurrentMap newConcurrentMapWithAggressiveConcurrency(int initalCapacity) { return new ConcurrentHashMap<>(initalCapacity, 0.75f, aggressiveConcurrencyLevel); } //...... }
ConcurrentCollections提供了newConcurrentMapLong及newConcurrentMapLongWithAggressiveConcurrency两个静态方法用于创建ConcurrentMapLong;其中newConcurrentMapLongWithAggressiveConcurrency方法创建initalCapacity为16,loadFactor为0.75f,concurrencyLevel为aggressiveConcurrencyLevel(Math.max(Runtime.getRuntime().availableProcessors() * 2, 16))的ConcurrentHashMap
小结ConcurrentMapLong继承了ConcurrentMap接口,并指定key类型为Long
ConcurrentHashMapLong实现了ConcurrentMapLong接口,它内部使用ConcurrentMap实现
ConcurrentCollections提供了newConcurrentMapLong及newConcurrentMapLongWithAggressiveConcurrency两个静态方法用于创建ConcurrentMapLong;其中newConcurrentMapLongWithAggressiveConcurrency方法创建initalCapacity为16,loadFactor为0.75f,concurrencyLevel为aggressiveConcurrencyLevel(Math.max(Runtime.getRuntime().availableProcessors() * 2, 16))的ConcurrentHashMap
docConcurrentMapLong
ConcurrentHashMapLong
ConcurrentCollections
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/34497.html
摘要:序本文主要研究一下的实现了,它是线程安全的其构造器要求输入及越大表示新数据权重越大旧数据权重越小返回的是的值,不过它存储的是的形式,返回的时候使用转换会方法使用计算新值,然后使用方法来实现原子更新实例方法测试算法的计算逻辑测试 序 本文主要研究一下Elasticsearch的ExponentiallyWeightedMovingAverage ExponentiallyWeighted...
摘要:序本文主要研究一下的继承了接口提供静态方法用于更方便地使用实例在中使用关闭了小结提供静态方法用于更方便地使用 序 本文主要研究一下Elasticsearch的Releasables Releasable elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/lease/Releasable.java publ...
摘要:序本文主要研究一下的接口定义了方法,该方法返回,另外还定义了一个方法,默认返回的方法返回了一系列,其中包括等要求不得小于要求是对开启的话要求是以后,避免小结接口定义了方法,该方法返回,另外还定义了一个方法,默认返回的方法返回了一 序 本文主要研究一下Elasticsearch的BootstrapCheck BootstrapCheck elasticsearch-7.0.1/serve...
摘要:序本文主要研究一下的实现了接口,其方法使用来选择数组的下标,然后返回该下标的值的构造器创建了两个,分别是及方法执行的是方法执行的是的及方法都接收参数,通过该来选取小结实现了接口,其方法使用来选择数组的下标,然后返回该下标的值的构造器创 序 本文主要研究一下Elasticsearch的RoundRobinSupplier RoundRobinSupplier elasticsearch-...
摘要:序本文主要研究一下的实现了接口,它的构造器要求输入,同时构造了变量方法会先使用将由设置为,如果成功则执行代理的的方法方法则返回值实例方法验证了顺序多次执行的场景方法则验证了并发多次执行的场景则验证了使用作为的场景小结实现了接口,它的构 序 本文主要研究一下Elasticsearch的RunOnce RunOnce elasticsearch-7.0.1/server/src/main/...
阅读 2454·2023-04-25 14:15
阅读 2397·2021-11-04 16:11
阅读 3205·2021-10-14 09:42
阅读 291·2019-08-30 15:52
阅读 2684·2019-08-30 14:03
阅读 3408·2019-08-30 13:00
阅读 1990·2019-08-26 11:40
阅读 3157·2019-08-26 10:25