Interface ThreadContextRestorer
-
- 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 ThreadContextRestorer
Restores the prior context on a thread after a contextual task or action completes.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidendContext()Invoked by the Jakarta EE Product Provider to remove the thread context that theThreadContextSnapshotbegan on this thread and restore the previous context that was on the thread prior to that point.
-
-
-
Method Detail
-
endContext
void endContext() throws IllegalStateExceptionInvoked by the Jakarta EE Product Provider to remove the thread context that theThreadContextSnapshotbegan on this thread and restore the previous context that was on the thread prior to that point. The Jakarta EE Product Provider must invoke theendContextmethod exactly once for eachThreadContextRestorerinstance that it obtains and on the same thread from which the Jakarta EE Product Provider obtained it by invokingThreadContextSnapshot.begin.Typically, patterns such as the following will be observed:
restorerA1 = contextA_snapshot1.begin(); restorerB1 = contextB_snapshot1.begin(); restorerC1 = contextC_snapshot1.begin(); ... restorerC1.endContext(); restorerB1.endContext(); restorerA1.endContext();
However, more advanced sequences such as the following are also valid: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();
- Throws:
IllegalStateException- if invoked more than once on the same instance.- Since:
- 3.0
-
-