Annotation Type CurrentThreadContext
Declares that a method should be called with its current ThreadContext set to one created
with the specified settings.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classUtil class used for inline creation ofCurrentThreadContextannotation instances. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionString[]Defines the set of thread context types to clear from the thread where the action or task executes.String[]Defines the set of thread context types to capture from the thread that contextualizes an action or task.booleanDefines that the current thread context should be removed.String[]Defines a set of thread context types that are essentially ignored, in that they are neither captured nor are they propagated or cleared from thread(s) that execute the action or task.
-
Element Details
-
remove
boolean removeDefines that the current thread context should be removed. This is mutually exclusive with the other settings.- Returns:
- a boolean indicating if the current thread context should be removed. Defaults to false.
- Default:
false
-
cleared
String[] clearedDefines the set of thread context types to clear from the thread where the action or task executes. The previous context is resumed on the thread after the action or task ends.
By default, no context is cleared/suspended from execution thread.
ThreadContext.ALL_REMAININGis automatically appended to the set of cleared context if neither thepropagated()set nor theunchanged()set includeThreadContext.ALL_REMAINING.Constants for specifying some of the core context types are provided on
ThreadContext. Other thread context types must be defined by the specification that defines the context type or by a related MicroProfile specification.A
CurrentThreadContextmust fail to initialise, raisingDefinitionExceptionon application startup, if a context type specified within this set is unavailable or if thepropagated()and/orunchanged()set includes one or more of the same types as this set.- Returns:
- an array of strings of thread context types to clear.
- Default:
{}
-
propagated
String[] propagatedDefines the set of thread context types to capture from the thread that contextualizes an action or task. This context is later re-established on the thread(s) where the action or task executes.
The default set of propagated thread context types is
ThreadContext.ALL_REMAINING, which includes all available thread context types that support capture and propagation to other threads, except for those that are explicitlycleared.Constants for specifying some of the core context types are provided on
ThreadContext. Other thread context types must be defined by the specification that defines the context type or by a related MicroProfile specification.Thread context types which are not otherwise included in this set or in the
unchanged()set are cleared from the thread of execution for the duration of the action or task.A
CurrentThreadContextmust fail to initialise, raisingDefinitionExceptionon application startup, if a context type specified within this set is unavailable or if thecleared()and/orunchanged()set includes one or more of the same types as this set.- Returns:
- an array of strings of thread context types to propagate.
- Default:
{"Remaining"}
-
unchanged
String[] unchangedDefines a set of thread context types that are essentially ignored, in that they are neither captured nor are they propagated or cleared from thread(s) that execute the action or task.
Constants for specifying some of the core context types are provided on
ThreadContext. Other thread context types must be defined by the specification that defines the context type or by a related MicroProfile specification.The configuration
unchangedcontext is provided for advanced patterns where it is desirable to leave certain context types on the executing thread.For example, to run as the current application, but under the transaction of the thread where the task executes:
@WithThreadContext(unchanged = ThreadContext.TRANSACTION, propagated = ThreadContext.APPLICATION, cleared = ThreadContext.ALL_REMAINING) public void method() { ... task = SmallRyeThreadContext.getCurrentThreadContext().contextualRunnable(new MyTransactionalTask()); ... // on another thread, tx.begin(); ... task.run(); // runs under the transaction due to 'unchanged' tx.commit(); }A
CurrentThreadContextmust fail to initialise, raisingDefinitionExceptionon application startup, if a context type specified within this set is unavailable or if thecleared()and/orpropagated()set includes one or more of the same types as this set.- Returns:
- an array of strings of thread context types to be ignored.
- Default:
{}
-