Class StatsNamedContainer<V>

java.lang.Object
org.hibernate.stat.internal.StatsNamedContainer<V>

public final class StatsNamedContainer<V> extends Object
Decorates a ConcurrentHashMap implementation to make sure the methods are being used correctly for the purpose of Hibernate's statistics. In particular, we do like the semantics of ConcurrentHashMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>) but not its performance.

See HHH-13527.

  • Constructor Details

    • StatsNamedContainer

      public StatsNamedContainer(int capacity, int concurrencyLevel)
      Creates a bounded container - based on BoundedConcurrentHashMap
    • StatsNamedContainer

      public StatsNamedContainer()
      Creates an unbounded container - based on ConcurrentHashMap
  • Method Details

    • clear

      public void clear()
    • keysAsArray

      public String[] keysAsArray()
      This method is inherently racy and expensive. Only use on non-hot paths, and only to get a recent snapshot.
      Returns:
      all keys in string form.
    • getOrCompute

      public @Nullable V getOrCompute(String key, Function<String,V> function)
      Similar semantics as you'd get by invoking ConcurrentMap.computeIfAbsent(Object, Function), but we check for the key existence first. This is technically a redundant check, but it has been shown to perform better when the key existing is very likely, as in our case. Most notably, the ConcurrentHashMap implementation might block other accesses for the sake of making sure the function is invoked at most once: we don't need this guarantee, and prefer to reduce risk of blocking.
    • get

      public @Nullable V get(String key)