@FunctionalInterface
public interface ThreadContextRestorer
Modifier and Type | Method and Description |
---|---|
void |
endContext()
Invoked by the Jakarta EE Product Provider to remove the thread context that
the
ThreadContextSnapshot began on this thread and restore the previous
context that was on the thread prior to that point. |
void endContext() throws java.lang.IllegalStateException
ThreadContextSnapshot
began on this thread and restore the previous
context that was on the thread prior to that point. The Jakarta EE Product Provider
must invoke the endContext
method exactly
once for each ThreadContextRestorer
instance that it obtains
and on the same thread from which the Jakarta EE Product Provider obtained it
by invoking ThreadContextSnapshot.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();
java.lang.IllegalStateException
- if invoked more than once on the same instance.