Top Description Inners Fields Constructors Methods
org.springframework.core

public Class NamedThreadLocal<T>

extends ThreadLocal<T>
Class Inheritance
Known Direct Subclasses
org.springframework.core.NamedThreadLocal.SuppliedNamedThreadLocal
Type Parameters
<T>
the value type
Imports
java.util.Objects, java.util.function.Supplier, org.springframework.util.Assert

ThreadLocal subclass that exposes a specified name as toString() result (allowing for introspection).
Authors
Juergen Hoeller, Qimiao Chen
Since
2.5.2
See Also
NamedInheritableThreadLocal

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
NamedThreadLocal.SuppliedNamedThreadLocal<
the type of the named thread local's value
T
>

An extension of NamedThreadLocal that obtains its initial value from the specified Supplier.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public
NamedThreadLocal(String
a descriptive name for this ThreadLocal
name
)

Create a new NamedThreadLocal with the given name.

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public static <
the type of the named thread local's value
S
>
ThreadLocal<S>

Returns:

a new named thread local
withInitial
(String
a descriptive name for the thread local
name
,
Supplier<? extends S>
the supplier to be used to determine the initial value
supplier
)

Create a named thread local variable.

Inherited from java.lang.ThreadLocal:
getinitialValueremovesetwithInitial

Field Detail

nameback to summary
private final String name

Constructor Detail

NamedThreadLocalback to summary
public NamedThreadLocal(String name)

Create a new NamedThreadLocal with the given name.

Parameters
name:String

a descriptive name for this ThreadLocal

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
withInitialback to summary
public static <S> ThreadLocal<S> withInitial(String name, Supplier<? extends S> supplier)

Create a named thread local variable. The initial value of the variable is determined by invoking the get method on the Supplier.

Parameters
<S>
the type of the named thread local's value
name:String

a descriptive name for the thread local

supplier:Supplier<? extends S>

the supplier to be used to determine the initial value

Returns:ThreadLocal<S>

a new named thread local

Since
6.1
org.springframework.core back to summary

private final Class NamedThreadLocal.SuppliedNamedThreadLocal<T>

extends NamedThreadLocal<T>
Class Inheritance
Type Parameters
<T>
the type of the named thread local's value

An extension of NamedThreadLocal that obtains its initial value from the specified Supplier.

Field Summary

Modifier and TypeField and Description
private final Supplier<? extends T>

Constructor Summary

AccessConstructor and Description
pack-priv
SuppliedNamedThreadLocal(String name, Supplier<? extends T> supplier)

Method Summary

Modifier and TypeMethod and Description
protected T
initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable.

Inherited from org.springframework.core.NamedThreadLocal:
toStringwithInitial

Field Detail

supplierback to summary
private final Supplier<? extends T> supplier

Constructor Detail

SuppliedNamedThreadLocalback to summary
pack-priv SuppliedNamedThreadLocal(String name, Supplier<? extends T> supplier)

Method Detail

initialValueback to summary
protected T initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Doc from java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable. This method will be invoked the first time a thread accesses the variable with the get method, unless the thread previously invoked the set method, in which case the initialValue method will not be invoked for the thread. Normally, this method is invoked at most once per thread, but it may be invoked again in case of subsequent invocations of remove followed by get.

Returns:T

the initial value for this thread-local

Annotations
@Override