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 TypeMethodDescriptionvoidInvoked by theManagedExecutororThreadContextto remove the thread context managed by thisThreadContextControllerinstance and restore the previous context that was on the thread before theThreadContextControllerapplied the context to the thread.
-
Method Details
-
endContext
Invoked by the
ManagedExecutororThreadContextto remove the thread context managed by thisThreadContextControllerinstance and restore the previous context that was on the thread before theThreadContextControllerapplied the context to the thread. TheManagedExecutororThreadContextmust invoke theendContextmethod exactly once for eachThreadContextControllerinstance 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.
-