@FunctionalInterface public interface ThreadContextController
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.
Modifier and Type | Method and Description |
---|---|
void |
endContext()
Invoked by the
ManagedExecutor or
ThreadContext to remove the thread context managed by
this ThreadContextController instance and restore the previous
context that was on the thread before the ThreadContextController
applied the context to the thread. |
void endContext() throws IllegalStateException
Invoked by the ManagedExecutor
or
ThreadContext
to remove the thread context managed by
this ThreadContextController
instance and restore the previous
context that was on the thread before the ThreadContextController
applied the context to the thread. The ManagedExecutor
or
ThreadContext
must invoke the endContext
method exactly
once for each ThreadContextController
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();
IllegalStateException
- if invoked more than once on the same instance.Copyright © 2019 Eclipse Foundation. All rights reserved.