Class ThreadLocalContext
A participating value is created using create(). Calling capture() takes one snapshot of all
participating values, which can subsequently be activated around work on another thread. Activation is nested and
restores the context that was previously present on that thread.
Participating values remain regular thread locals on the hot path. The shared registry is only consulted when a context is captured or activated, so merely entering and leaving a request context does not allocate a map. Removing a participating value removes its thread-local value in the usual way; once the final child is removed, there is therefore no request context left on that thread.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA reusable snapshot of the context that was active whencapture()was called. -
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadLocalContext.Snapshotcapture()Returns an immutable snapshot of every context value active on the current thread.static <T> ThreadLocal<T> create()Creates a thread local whose value participates in this shared context.
-
Method Details
-
create
Creates a thread local whose value participates in this shared context.The returned holder is an ordinary
ThreadLocal; participation only adds work when a snapshot is captured or activated. -
capture
Returns an immutable snapshot of every context value active on the current thread.
-