Top Description Fields Constructors Methods
com.fasterxml.jackson.core.util

public final Class InternCache

extends ConcurrentHashMap<String, String>
Class Inheritance
Imports
java.util.concurrent.ConcurrentHashMap, java.util.concurrent.locks.ReentrantLock

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.

Field Summary

Modifier and TypeField and Description
private static final int
DEFAULT_MAX_ENTRIES

Size to use is somewhat arbitrary, so let's choose something that's neither too small (low hit ratio) nor too large (waste of memory).

public static final InternCache
private final ReentrantLock
lock

As 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

AccessConstructor and Description
public
public
InternCache(int maxSize, float loadFactor, int concurrency)

Method Summary

Modifier and TypeMethod and Description
public String
intern(String input)

Inherited from java.util.concurrent.ConcurrentHashMap:
clearcomputecomputeIfAbsentcomputeIfPresentcontainscontainsKeycontainsValueelementsentrySetequalsforEachforEachforEachforEachEntryforEachEntryforEachKeyforEachKeyforEachValueforEachValuegetgetOrDefaulthashCodeisEmptykeyskeySetkeySetmappingCountmergenewKeySetnewKeySetputputAllputIfAbsentreducereduceEntriesreduceEntriesreduceEntriesToDoublereduceEntriesToIntreduceEntriesToLongreduceKeysreduceKeysreduceKeysToDoublereduceKeysToIntreduceKeysToLongreduceToDoublereduceToIntreduceToLongreduceValuesreduceValuesreduceValuesToDoublereduceValuesToIntreduceValuesToLongremoveremovereplacereplacereplaceAllsearchsearchEntriessearchKeyssearchValuessizetoStringvalues

Field Detail

DEFAULT_MAX_ENTRIESback to summary
private static final int DEFAULT_MAX_ENTRIES

Size 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

instanceback to summary
public static final InternCache instance
lockback to summary
private final ReentrantLock lock

As minor optimization let's try to avoid "flush storms", cases where multiple threads might try to concurrently flush the map.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.ConcurrentHashMap.serialVersionUID.

Constructor Detail

InternCacheback to summary
public InternCache()
InternCacheback to summary
public InternCache(int maxSize, float loadFactor, int concurrency)

Method Detail

internback to summary
public String intern(String input)