Top Description Methods
jakarta.enterprise.concurrent.spi

public Interface ThreadContextRestorer

Annotations
@FunctionalInterface

Restores the prior context on a thread after a contextual task or action completes.

Method Summary

Modifier and TypeMethod and Description
public 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.

Method Detail

endContextback to summary
public void endContext() throws IllegalStateException

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