Class DataStructures
- java.lang.Object
-
- org.glassfish.jersey.internal.util.collection.DataStructures
-
public final class DataStructures extends java.lang.Object
Utility class, which tries to pickup the best collection implementation depending on running environment.- Since:
- 2.3
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CONCURENCY_LEVEL
Default concurrency level calculated based on the number of available CPUs.private static java.lang.Class<?>
LTQ_CLASS
-
Constructor Summary
Constructors Constructor Description DataStructures()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static int
ceilingNextPowerOfTwo(int x)
static <K,V>
java.util.concurrent.ConcurrentMap<K,V>createConcurrentMap()
Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16).static <K,V>
java.util.concurrent.ConcurrentMap<K,V>createConcurrentMap(int initialCapacity)
Creates a new, empty map with an initial table size accommodating the specified number of elements without the need to dynamically resize.static <K,V>
java.util.concurrent.ConcurrentMap<K,V>createConcurrentMap(int initialCapacity, float loadFactor, int concurrencyLevel)
Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity
), table density (loadFactor
), and number of concurrently updating threads (concurrencyLevel
).static <K,V>
java.util.concurrent.ConcurrentMap<K,V>createConcurrentMap(java.util.Map<? extends K,? extends V> map)
Creates a new map with the same mappings as the given map.static <E> java.util.concurrent.BlockingQueue<E>
createLinkedTransferQueue()
Create an instance of aBlockingQueue
that is based onLinkedTransferQueue
implementation from JDK 7.private static java.lang.Class<?>
getAndVerify(java.lang.String cn)
-
-
-
Method Detail
-
ceilingNextPowerOfTwo
private static int ceilingNextPowerOfTwo(int x)
-
getAndVerify
private static java.lang.Class<?> getAndVerify(java.lang.String cn) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
createLinkedTransferQueue
public static <E> java.util.concurrent.BlockingQueue<E> createLinkedTransferQueue()
Create an instance of aBlockingQueue
that is based onLinkedTransferQueue
implementation from JDK 7.When running on JDK 7 or higher, JDK
LinkedTransferQueue
implementation is used, on JDK 6 an internal Jersey implementation class is used.- Type Parameters:
E
- the type of elements held in the queue.- Returns:
- new instance of a
BlockingQueue
that is based onLinkedTransferQueue
implementation from JDK 7.
-
createConcurrentMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> createConcurrentMap()
Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16).On Oracle JDK, the factory method will return an instance of
ConcurrentHashMapV8
that is supposed to be available in JDK 8 and provides better performance and memory characteristics thanConcurrentHashMap
implementation from JDK 7 or earlier. On non-Oracle JDK, the factory instantiates the standardConcurrentHashMap
from JDK.- Returns:
- the map.
-
createConcurrentMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> createConcurrentMap(java.util.Map<? extends K,? extends V> map)
Creates a new map with the same mappings as the given map.On Oracle JDK, the factory method will return an instance of
ConcurrentHashMapV8
that is supposed to be available in JDK 8 and provides better performance and memory characteristics thanConcurrentHashMap
implementation from JDK 7 or earlier. On non-Oracle JDK, the factory instantiates the standardConcurrentHashMap
from JDK.- Parameters:
map
- the map.
-
createConcurrentMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> createConcurrentMap(int initialCapacity)
Creates a new, empty map with an initial table size accommodating the specified number of elements without the need to dynamically resize.On Oracle JDK, the factory method will return an instance of
ConcurrentHashMapV8
that is supposed to be available in JDK 8 and provides better performance and memory characteristics thanConcurrentHashMap
implementation from JDK 7 or earlier. On non-Oracle JDK, the factory instantiates the standardConcurrentHashMap
from JDK.- Parameters:
initialCapacity
- The implementation performs internal sizing to accommodate this many elements.- Throws:
java.lang.IllegalArgumentException
- if the initial capacity of elements is negative.
-
createConcurrentMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> createConcurrentMap(int initialCapacity, float loadFactor, int concurrencyLevel)
Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity
), table density (loadFactor
), and number of concurrently updating threads (concurrencyLevel
).On Oracle JDK, the factory method will return an instance of
ConcurrentHashMapV8
that is supposed to be available in JDK 8 and provides better performance and memory characteristics thanConcurrentHashMap
implementation from JDK 7 or earlier. On non-Oracle JDK, the factory instantiates the standardConcurrentHashMap
from JDK.- Parameters:
initialCapacity
- the initial capacity. The implementation performs internal sizing to accommodate this many elements, given the specified load factor.loadFactor
- the load factor (table density) for establishing the initial table size.concurrencyLevel
- the estimated number of concurrently updating threads. The implementation may use this value as a sizing hint.- Throws:
java.lang.IllegalArgumentException
- if the initial capacity is negative or the load factor or concurrencyLevel are not positive.
-
-