Class InternCache
- All Implemented Interfaces:
Serializable, ConcurrentMap<String,String>, Map<String, String>
Singleton class that adds a simple first-level cache in front of
regular String.intern() functionality. This is done as a minor
performance optimization, to avoid calling native intern() method
in cases where same String is being interned multiple times.
Note: that this class extends
ConcurrentHashMap is an implementation
detail -- no code should ever directly call ConcurrentHashMap methods.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class ConcurrentHashMap
ConcurrentHashMap.KeySetView<K,V> Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intSize to use is somewhat arbitrary, so let's choose something that's neither too small (low hit ratio) nor too large (waste of memory).static final InternCacheprivate final ReentrantLockAs minor optimization let's try to avoid "flush storms", cases where multiple threads might try to concurrently flush the map.private static final long -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class ConcurrentHashMap
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, get, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, put, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, valuesMethods inherited from class AbstractMap
clone
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
DEFAULT_MAX_ENTRIES
private static final int DEFAULT_MAX_ENTRIESSize to use is somewhat arbitrary, so let's choose something that's neither too small (low hit ratio) nor too large (waste of memory).One consideration is possible attack via colliding
String.hashCode(); because of this, limit to reasonably low setting.Increased to 200 (from 100) in 2.18
- See Also:
-
instance
-
lock
As minor optimization let's try to avoid "flush storms", cases where multiple threads might try to concurrently flush the map.
-
-
Constructor Details
-
InternCache
public InternCache() -
InternCache
public InternCache(int maxSize, float loadFactor, int concurrency)
-
-
Method Details
-
intern
-