Interface ThreadContextController
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents context that is applied to a particular thread, along with any state that is associated with it or that is necessary for restoring the previous context afterward.
When the context is no longer needed on the thread, the
ManagedExecutor
or ThreadContext
must invoke the
endContext
method.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked by theManagedExecutor
orThreadContext
to remove the thread context managed by thisThreadContextController
instance and restore the previous context that was on the thread before theThreadContextController
applied the context to the thread.
-
Method Details
-
endContext
Invoked by the
ManagedExecutor
orThreadContext
to remove the thread context managed by thisThreadContextController
instance and restore the previous context that was on the thread before theThreadContextController
applied the context to the thread. TheManagedExecutor
orThreadContext
must invoke theendContext
method exactly once for eachThreadContextController
instance that it creates.Typically, patterns such as the following will be observed:
controllerA1 = contextSnapshotA.begin(); controllerB1 = contextSnapshotB.begin(); controllerC1 = contextSnapshotC.begin(); ... controllerC1.endContext(); controllerB1.endContext(); controllerA1.endContext();
However, more advanced sequences such as the following are also valid:
controllerA1 = contextSnapshotA.begin(); controllerB1 = contextSnapshotB.begin(); ... controllerC1 = contextSnapshotC.begin(); ... controllerC1.endContext(); ... controllerB2 = contextSnapshotB.begin(); controllerC2 = contextSnapshotC.begin(); ... controllerC2.endContext(); controllerB2.endContext(); ... controllerB1.endContext(); controllerA1.endContext();
- Throws:
IllegalStateException
- if invoked more than once on the same instance.
-