java.lang · java.base · since Java 1.2
ThreadLocal
public class ThreadLocal<T>Per-thread variable storage: each thread sees its own value. Historically used for non-thread-safe helpers and request context; ScopedValue is the modern successor.
Key methods
static <S> ThreadLocal<S> withInitial(Supplier<S>) | Create with a per-thread initializer. |
T get() / void set(T value) | The calling thread's copy. |
void remove() | Delete this thread's entry — mandatory hygiene in pooled threads. |