Example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

List of usage examples for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap.

Prototype

public ConcurrentHashMap(int initialCapacity, float loadFactor) 

Source Link

Document

Creates a new, empty map with an initial table size based on the given number of elements ( initialCapacity ) and initial table density ( loadFactor ).

Usage

From source file:Main.java

public static <K, V> ConcurrentMap<K, V> createConcurrentMap(int initialCapacity, float loadFactor) {
    return new ConcurrentHashMap<K, V>(initialCapacity, loadFactor);
}

From source file:Main.java

/**
 * Create a properly sized {@link ConcurrentHashMap} based on the given expected number of elements and an
 * explicit load factor//from w w w.  j a v a 2s. c  om
 *
 * @param expectedNumberOfElements The expected number of elements for the created map
 * @param loadFactor The collection load factor
 * @param <K> The map key type
 * @param <V> The map value type
 *
 * @return The created map.
 */
public static <K, V> ConcurrentHashMap<K, V> concurrentMap(int expectedNumberOfElements, float loadFactor) {
    final int size = expectedNumberOfElements + 1 + (int) (expectedNumberOfElements * loadFactor);
    return new ConcurrentHashMap<K, V>(size, loadFactor);
}