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.

@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.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.
  • Method Details

    • endContext

      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();
       
      Throws:
      IllegalStateException - if invoked more than once on the same instance.