org.elasticsearch.common.util.concurrent.ConcurrentCollections Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.common.util.concurrent;
import java.util.Deque;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedTransferQueue;
public abstract class ConcurrentCollections {
static final int aggressiveConcurrencyLevel;
static {
aggressiveConcurrencyLevel = Math.max(Runtime.getRuntime().availableProcessors() * 2, 16);
}
/**
* Creates a new CHM with an aggressive concurrency level, aimed at high concurrent update rate long living maps.
*/
public static ConcurrentMap newConcurrentMapWithAggressiveConcurrency() {
return newConcurrentMapWithAggressiveConcurrency(16);
}
/**
* Creates a new CHM with an aggressive concurrency level, aimed at high concurrent update rate long living maps.
*/
public static ConcurrentMap newConcurrentMapWithAggressiveConcurrency(int initalCapacity) {
return new ConcurrentHashMap<>(initalCapacity, 0.75f, aggressiveConcurrencyLevel);
}
public static ConcurrentMap newConcurrentMap() {
return new ConcurrentHashMap<>();
}
public static Set newConcurrentSet() {
return ConcurrentHashMap.newKeySet();
}
public static Queue newQueue() {
return new ConcurrentLinkedQueue<>();
}
public static Deque newDeque() {
return new ConcurrentLinkedDeque<>();
}
public static BlockingQueue newBlockingQueue() {
return new LinkedTransferQueue<>();
}
private ConcurrentCollections() {
}
}