Package org.hibernate.stat.internal
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 ofConcurrentHashMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)
but not its performance.See HHH-13527.
-
-
Constructor Summary
Constructors Constructor Description StatsNamedContainer()
Creates an unbounded container - based on ConcurrentHashMapStatsNamedContainer(int capacity, int concurrencyLevel)
Creates a bounded container - based on BoundedConcurrentHashMap
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
@Nullable V
get(String key)
@Nullable V
getOrCompute(String key, Function<String,V> function)
Similar semantics as you'd get by invokingConcurrentMap.computeIfAbsent(Object, Function)
, but we check for the key existence first.String[]
keysAsArray()
This method is inherently racy and expensive.
-
-
-
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.- Returns:
- all keys in string form.
-
getOrCompute
public @Nullable V getOrCompute(String key, Function<String,V> function)
Similar semantics as you'd get by invokingConcurrentMap.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.
-
-