Package org.hibernate.stat.internal
Class StatsNamedContainer<V>
java.lang.Object
org.hibernate.stat.internal.StatsNamedContainer<V>
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 Summary
ConstructorsConstructorDescriptionCreates an unbounded container - based on ConcurrentHashMapStatsNamedContainer
(int capacity, int concurrencyLevel) Creates a bounded container - based on BoundedConcurrentHashMap -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
@Nullable V
@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[]
This method is inherently racy and expensive.
-
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
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
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. -
get
-