- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ThreadContextSnapshotAn immutable snapshot of a particular type of thread context.
The captured context represented by this snapshot can be applied to any number of threads, including concurrently.
Any state that is associated with context applied to a thread should be kept, not within the snapshot, but within the distinct
ThreadContextRestorerinstance that this
ThreadContextSnapshotcreates each time it is applied to a thread.
ThreadContextRestorer begin()Applies the captured thread context snapshot to the current thread and returns a distinct
ThreadContextRestorerinstance tracks the context's life cycle, including any state that is associated with it or that is necessary for restoring the previous context.
For each invocation of this method, the Jakarta EE Product Provider must invoke the corresponding
endContextmethod exactly once, such that the previous context is restored on the thread. If the Jakarta EE Product Provider sequentially begins multiple
ThreadContextRestorerinstances on a thread, it must invoke the corresponding
endContextmethods in reverse order.
- restorer instance that reverts the state of this context type on the thread to what it was prior to applying this snapshot.