Package org.springframework.core

# Class NamedThreadLocal<T>

java.lang.Object
java.lang.ThreadLocal<T>
org.springframework.core.NamedThreadLocal<T>

Type Parameters:
  `T` - the value type

public class NamedThreadLocal<T> extends ThreadLocal<T>
`ThreadLocal` subclass that exposes a specified name as `toString()` result (allowing for introspection).

Since:
  2.5.2
Author:
  Juergen Hoeller, Qimiao Chen
See Also:
  - `NamedInheritableThreadLocal`

## Constructor Summary

Constructors
Constructor
Description
`NamedThreadLocal(String name)`
Create a new NamedThreadLocal with the given name.

## Method Summary

Modifier and Type
Method
Description
`String`
`toString()`
`static <S> ThreadLocal<S>`
`withInitial(String name, Supplier<? extends S> supplier)`
Create a named thread local variable.

### Methods inherited from class java.lang.ThreadLocal

`get, initialValue, remove, set, withInitial`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### NamedThreadLocal

public NamedThreadLocal(String name)
Create a new NamedThreadLocal with the given name.

Parameters:
  `name` - a descriptive name for this ThreadLocal

## Method Details

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### withInitial

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`.

Type Parameters:
  `S` - the type of the named thread local's value
Parameters:
  `name` - a descriptive name for the thread local
  `supplier` - the supplier to be used to determine the initial value
Returns:
  a new named thread local
Since:
  6.1