インターフェース ThreadContextRestorer

関数インターフェース:
これは関数インターフェースであるため、ラムダ式またはメソッド参照の割り当てターゲットとして使用できます。

@FunctionalInterfaceSE public interface ThreadContextRestorer
コンテキストタスクまたはアクションが完了した後、スレッドの前のコンテキストを復元します。
  • メソッドのサマリー

    修飾子と型
    メソッド
    説明
    void
    Jakarta EE Product Provider によって呼び出され、ThreadContextSnapshot がこのスレッドで開始したスレッドコンテキストを削除し、その時点より前にスレッド上にあった以前のコンテキストを復元します。
  • メソッドの詳細

    • endContext

      void endContext() throws IllegalStateExceptionSE
      Jakarta EE Product Provider によって呼び出され、ThreadContextSnapshot がこのスレッドで開始したスレッドコンテキストを削除し、その時点より前にスレッド上にあった以前のコンテキストを復元します。Jakarta EE Product Provider は、取得する ThreadContextRestorer インスタンスごとに endContext メソッドを 1 回だけ呼び出す必要があり、Jakarta EE Product Provider が ThreadContextSnapshot.begin を呼び出して取得したのと同じスレッドで実行する必要があります。

      通常、次のようなパターンが観測されます。

       restorerA1 = contextA_snapshot1.begin();
       restorerB1 = contextB_snapshot1.begin();
       restorerC1 = contextC_snapshot1.begin();
       ...
       restorerC1.endContext();
       restorerB1.endContext();
       restorerA1.endContext();
       
      ただし、次のようなより高度なシーケンスも有効です。
       restorerA1 = contextA_snapshot1.begin();
       restorerB1 = contextB_snapshot1.begin();
       ...
       restorerC1 = contextC_snapshot1.begin();
       ...
       restorerC1.endContext();
       ...
       restorerB2 = contextB_snapshot2.begin();
       restorerC2 = contextC_snapshot2.begin();
       ...
       restorerC2.endContext();
       restorerB2.endContext();
       ...
       restorerB1.endContext();
       restorerA1.endContext();
       
      例外:
      IllegalStateExceptionSE - 同じインスタンスで複数回呼び出された場合。
      導入:
      3.0