Annotation Type CurrentThreadContext


  • @InterceptorBinding
    @Retention(RUNTIME)
    @Target({METHOD,TYPE})
    public @interface CurrentThreadContext

    Declares that a method should be called with its current ThreadContext set to one created with the specified settings.

    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String[] cleared
      Defines the set of thread context types to clear from the thread where the action or task executes.
      String[] propagated
      Defines the set of thread context types to capture from the thread that contextualizes an action or task.
      boolean remove
      Defines that the current thread context should be removed.
      String[] unchanged
      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 Detail

      • remove

        boolean remove
        Defines 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[] cleared

        Defines 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_REMAINING is automatically appended to the set of cleared context if neither the propagated() set nor the unchanged() set include ThreadContext.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 CurrentThreadContext must fail to initialise, raising DefinitionException on application startup, if a context type specified within this set is unavailable or if the propagated() and/or unchanged() 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[] propagated

        Defines 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 explicitly cleared.

        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 CurrentThreadContext must fail to initialise, raising DefinitionException on application startup, if a context type specified within this set is unavailable or if the cleared() and/or unchanged() 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[] unchanged

        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.

        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 unchanged context 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 CurrentThreadContext must fail to initialise, raising DefinitionException on application startup, if a context type specified within this set is unavailable or if the cleared() and/or propagated() 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:
        {}