Class 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 but not how it performs. See also: - -
    • Constructor Detail

      • 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 Detail

      • 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.
        all keys in string form.
      • getOrCompute

        public 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 V get​(String key)