Class DefaultThreadContextMap
- All Implemented Interfaces:
Serializable,ThreadContextMap,ReadOnlyStringMap
ThreadContextMap
An instance of UnmodifiableArrayBackedMap can be represented as a single Object[], which can safely
be stored on the ThreadLocal with no fear of classloader-related memory leaks.
Performance of the underlying UnmodifiableArrayBackedMap exceeds
HashMap in all supported operations other than get(). Note that get() performance scales
linearly with the current map size, and callers are advised to minimize this work.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty name ("isThreadContextMapInheritable") for selectingInheritableThreadLocal(value "true") or plainThreadLocal(value is not "true") in the implementation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the context.booleancontainsKey(String key) Determines if the key is in the context.boolean<V> voidforEach(BiConsumer<String, ? super V> action) Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.<V,S> void forEach(TriConsumer<String, ? super V, S> action, S state) Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.Gets the context identified by thekeyparameter.getCopy()Gets a non-nullmutable copy of current thread's context Map.Returns an immutable view on the context Map ornullif the context map is empty.<V> VReturns the value for the specified key, ornullif the specified key does not exist in this collection.inthashCode()booleanisEmpty()Returns true if the Map is empty.voidPuts a context value (theoparameter) as identified with thekeyparameter into the current thread's context map.voidvoidRemoves the context identified by thekeyparameter.voidintsize()Returns the number of key-value pairs in this collection.toMap()Returns a non-nullmutableMap<String, String>containing a snapshot of this data structure.toString()
-
Field Details
-
INHERITABLE_MAP
Property name ("isThreadContextMapInheritable") for selectingInheritableThreadLocal(value "true") or plainThreadLocal(value is not "true") in the implementation.- See Also:
-
-
Constructor Details
-
DefaultThreadContextMap
public DefaultThreadContextMap() -
DefaultThreadContextMap
Deprecated.Since 2.24.0. UseNoOpThreadContextMapfor a no-op implementation.
-
-
Method Details
-
put
Description copied from interface:ThreadContextMapPuts a context value (theoparameter) as identified with thekeyparameter into the current thread's context map.If the current thread does not have a context map it is created as a side effect.
- Specified by:
putin interfaceThreadContextMap- Parameters:
key- The key name.value- The key value.
-
putAll
-
get
Description copied from interface:ThreadContextMapGets the context identified by thekeyparameter.This method has no side effects.
- Specified by:
getin interfaceThreadContextMap- Parameters:
key- The key to locate.- Returns:
- The value associated with the key or null.
-
remove
Description copied from interface:ThreadContextMapRemoves the context identified by thekeyparameter.- Specified by:
removein interfaceThreadContextMap- Parameters:
key- The key to remove.
-
removeAll
- Since:
- 2.8
-
clear
public void clear()Description copied from interface:ThreadContextMapClears the context.- Specified by:
clearin interfaceThreadContextMap
-
toMap
Description copied from interface:ReadOnlyStringMapReturns a non-nullmutableMap<String, String>containing a snapshot of this data structure.- Specified by:
toMapin interfaceReadOnlyStringMap- Returns:
- a mutable copy of this data structure in
Map<String, String>form.
-
containsKey
Description copied from interface:ThreadContextMapDetermines if the key is in the context.- Specified by:
containsKeyin interfaceReadOnlyStringMap- Specified by:
containsKeyin interfaceThreadContextMap- Parameters:
key- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
forEach
Description copied from interface:ReadOnlyStringMapPerforms the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.Some implementations may not support structural modifications (adding new elements or removing elements) while iterating over the contents. In such implementations, attempts to add or remove elements from the
BiConsumer'sBiConsumer.accept(Object, Object)accept} method may cause aConcurrentModificationExceptionto be thrown.- Specified by:
forEachin interfaceReadOnlyStringMap- Type Parameters:
V- type of the value.- Parameters:
action- The action to be performed for each key-value pair in this collection.
-
forEach
Description copied from interface:ReadOnlyStringMapPerforms the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.The third parameter lets callers pass in a stateful object to be modified with the key-value pairs, so the TriConsumer implementation itself can be stateless and potentially reusable.
Some implementations may not support structural modifications (adding new elements or removing elements) while iterating over the contents. In such implementations, attempts to add or remove elements from the
TriConsumer'sacceptmethod may cause aConcurrentModificationExceptionto be thrown.- Specified by:
forEachin interfaceReadOnlyStringMap- Type Parameters:
V- type of the value.S- type of the third parameter.- Parameters:
action- The action to be performed for each key-value pair in this collection.state- the object to be passed as the third parameter to each invocation on the specified triconsumer.
-
getValue
Description copied from interface:ReadOnlyStringMapReturns the value for the specified key, ornullif the specified key does not exist in this collection.- Specified by:
getValuein interfaceReadOnlyStringMap- Parameters:
key- the key whose value to return.- Returns:
- the value for the specified key or
null.
-
getCopy
Description copied from interface:ThreadContextMapGets a non-nullmutable copy of current thread's context Map.- Specified by:
getCopyin interfaceThreadContextMap- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
Description copied from interface:ThreadContextMapReturns an immutable view on the context Map ornullif the context map is empty.- Specified by:
getImmutableMapOrNullin interfaceThreadContextMap- Returns:
- an immutable context Map or
null.
-
isEmpty
public boolean isEmpty()Description copied from interface:ThreadContextMapReturns true if the Map is empty.- Specified by:
isEmptyin interfaceReadOnlyStringMap- Specified by:
isEmptyin interfaceThreadContextMap- Returns:
- true if the Map is empty, false otherwise.
-
size
public int size()Description copied from interface:ReadOnlyStringMapReturns the number of key-value pairs in this collection.- Specified by:
sizein interfaceReadOnlyStringMap- Returns:
- the number of key-value pairs in this collection.
-
toString
-
hashCode
public int hashCode() -
equals
-