文档章节

聊聊Elasticsearch的ConcurrentMapLong

go4it
 go4it
发布于 06/03 22:37
字数 576
阅读 6
收藏 0

本文主要研究一下Elasticsearch的ConcurrentMapLong

ConcurrentMapLong

elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentMapLong.java

public interface ConcurrentMapLong<T> extends ConcurrentMap<Long, T> {

    T get(long key);

    T remove(long key);

    T put(long key, T value);

    T putIfAbsent(long key, T value);
}
  • ConcurrentMapLong继承了ConcurrentMap接口,并指定key类型为Long

ConcurrentHashMapLong

elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentHashMapLong.java

public class ConcurrentHashMapLong<T> implements ConcurrentMapLong<T> {

    private final ConcurrentMap<Long, T> map;

    public ConcurrentHashMapLong(ConcurrentMap<Long, T> 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<Long> keySet() {
        return map.keySet();
    }

    @Override
    public Collection<T> values() {
        return map.values();
    }

    @Override
    public Set<Entry<Long, T>> 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实现

ConcurrentCollections

elasticsearch-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 static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
        return new ConcurrentHashMap<>();
    }

    public static <V> ConcurrentMapLong<V> newConcurrentMapLong() {
        return new ConcurrentHashMapLong<>(ConcurrentCollections.<Long, V>newConcurrentMap());
    }

    public static <V> ConcurrentMapLong<V> newConcurrentMapLongWithAggressiveConcurrency() {
        return new ConcurrentHashMapLong<>(ConcurrentCollections.<Long, V>newConcurrentMapWithAggressiveConcurrency());
    }

    public static <K, V> ConcurrentMap<K, V> newConcurrentMapWithAggressiveConcurrency() {
        return newConcurrentMapWithAggressiveConcurrency(16);
    }

    public static <K, V> ConcurrentMap<K, V> 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

doc

© 著作权归作者所有

go4it
粉丝 85
博文 1034
码字总数 988857
作品 0
深圳
私信 提问
聊聊springboot elasticsearch autoconfigure

序 本文主要研究一下springboot elasticsearch autoconfigure ElasticsearchAutoConfiguration spring-boot-autoconfigure-2.1.4.RELEASE-sources.jar!/org/springframework/boot/autoconfi......

go4it
04/17
0
0
聊聊Elasticsearch的Releasables

序 本文主要研究一下Elasticsearch的Releasables Releasable elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/lease/Releasable.java Releasable继承了java.io.Closeab......

go4it
06/14
0
0
CentOS7 部署 ElasticSearch 集群

环境 主机名 IP 操作系统 ES 版本 es227 192.168.1.227 CentOS7.5 6.5.4 es228 192.168.1.228 CentOS7.5 6.5.4 es229 192.168.1.229 CentOS7.5 6.5.4 下载 elasticsearch-6.5.4.tar.gz --- 各......

俊赛潘安-才比管乐
2018/12/27
0
0
聊聊Elasticsearch的SizeBlockingQueue

序 本文主要研究一下Elasticsearch的SizeBlockingQueue SizeBlockingQueue elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java Si......

go4it
06/01
0
0
Elasticsearch存储空间不够导致索引只读的解决方法

问题描述 今天发现当天的索引在ES中并没有创建,logstash中不停的报错: 索引变成了只读: es报错,es报错也是索引只读错误 解决办法 经过分析,发现是因为ES所在服务器磁盘空间太低引起,具...

傲娇字符
01/17
0
0

没有更多内容

加载失败,请刷新页面

加载更多

日志相关---日志配置和过滤器

一、log4j日志简介 1.1、 Loggers 级别和介绍 Loggers组件在此系统中被分为八个级别:ALL、TRANCE、DEBUG、INFO、WARN、ERROR和FATAL、OFF。这八个级别是有顺序的, ##off表示关闭ALL < T...

spinachgit
11分钟前
1
0
六个面试题层层剖析——LongAddr原子类

并发编程面试题 (1)LongAddr的结构是怎样的? (2)当前线程应该访问Cell数组里面的哪一个Cell元素? (3)如何初始化Cell数组? (4)Cell数组如何扩容? (5)线程访问分配的Cell元素有冲...

须臾之余
13分钟前
3
0
MySQL-入门(二)

本部分主要是MySQL的常用函数和高级用法。 一、MySQL排序 排序关键字:order by 排序字段。后面写上要排序字段,排序字段可以有多个,多个采用逗号间隔,order by默认采用升序(asc)排序,可...

潜行-L
23分钟前
0
0
BAM转VCF的方法对比

1 使用GATK HaplotypeCaller #java -jar gatk.jar HaplotypeCaller --native-pair-hmm-threads 4 -R xx.fa -I xx.bam -O xx.vcf --native-pair-hmm-threads用来设置多线程,默认为4线程 2 sa......

悲催的古灵武士
32分钟前
0
0
软件架构设计原则之“KISS”的总结使用

今天聊一聊软件架构设计中的 KISS 原则。 对! 就是亲嘴的那个 “KISS”! 一定要多练习。 ... ... ... ... 作为一个程序员我是推荐理解为“亲嘴”的,可以很好的解决单身问题,但作为一个架...

Owen_Jia
34分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部