Class InternCache

All Implemented Interfaces:
Serializable, ConcurrentMap<String,String>, Map<String,String>

public final class InternCache extends ConcurrentHashMap<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:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • DEFAULT_MAX_ENTRIES

      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

      See Also:
    • instance

      public static final InternCache instance
    • lock

      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.
  • Constructor Details

    • InternCache

      public InternCache()
    • InternCache

      public InternCache(int maxSize, float loadFactor, int concurrency)
  • Method Details