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

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
public static final InternCache
private final Object
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 int
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).

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

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

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

MAX_ENTRIESback to summary
private static final int 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.

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)