Top Description Fields Constructors Methods
org.hibernate.stat.internal

public final Class StatsNamedContainer<V>

extends Object
Class Inheritance
Imports
java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.function.Function, org.hibernate.internal.util.NullnessUtil, org.hibernate.internal.util.collections.BoundedConcurrentHashMap, org.checkerframework.checker.nullness.qual.Nullable

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 its performance.

See HHH-13527.

Author
Sanne Grinovero

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<String, Object>
private static final Object

Constructor Summary

AccessConstructor and Description
public
StatsNamedContainer(int capacity, int concurrencyLevel)

Creates a bounded container - based on BoundedConcurrentHashMap

public
StatsNamedContainer()

Creates an unbounded container - based on ConcurrentHashMap

Method Summary

Modifier and TypeMethod and Description
public void
public @Nullable V
get(final String key)

public @Nullable V
getOrCompute(final String key, final Function<String, V> function)

Similar semantics as you'd get by invoking ConcurrentMap#computeIfAbsent(Object, Function), but we check for the key existence first.

public String[]

Returns:

all keys in string form.
keysAsArray
()

This method is inherently racy and expensive.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
private final ConcurrentMap<String, Object> map
NULL_TOKENback to summary
private static final Object NULL_TOKEN

Constructor Detail

StatsNamedContainerback to summary
public StatsNamedContainer(int capacity, int concurrencyLevel)

Creates a bounded container - based on BoundedConcurrentHashMap

StatsNamedContainerback to summary
public StatsNamedContainer()

Creates an unbounded container - based on ConcurrentHashMap

Method Detail

clearback to summary
public void clear()
getback to summary
public @Nullable V get(final String key)
getOrComputeback to summary
public @Nullable V getOrCompute(final String key, final 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.

Annotations
@SuppressWarnings:unchecked
keysAsArrayback to summary
public String[] keysAsArray()

This method is inherently racy and expensive. Only use on non-hot paths, and only to get a recent snapshot.

Returns:String[]

all keys in string form.