Annotation Type NamedInstance


  • @Qualifier
    @Retention(RUNTIME)
    @Target({FIELD,METHOD,TYPE,PARAMETER})
    public @interface NamedInstance

    This annotation is used to achieve out of the box ManagedExecutor and ThreadContext instance sharing through CDI injection.

    Qualifies a CDI injection point for a ManagedExecutor or ThreadContext with a unique name across the application.

    This annotation can be used in combination with the ManagedExecutorConfig or ThreadContextConfig annotation to define a new instance. For example,

      @Inject @NamedInstance("myExecutor") @ManagedExecutorConfig(maxAsync=10)
     ManagedExecutor myExecutor;
    
     @Inject @NamedInstance("myContext") @ThreadContextConfig(propagated = { ThreadContext.SECURITY, ThreadContext.CDI })
     ThreadContext myThreadContext;
     
     

    Once used as shown above, this annotation can be used on its own to qualify an injection point with the name of an existing instance. Injection points with the same value() then share the same underlying contextual instance. For example, referencing a name from the previous example,

      @Inject @NamedInstance("myExecutor")
     ManagedExecutor exec1;
    
     @Inject @NamedInstance("myContext")
     ThreadContext myContextPropagator;
     
     

    Alternatively, an application can use this annotation as a normal CDI qualifier, defining its own scope, producer, and disposer. For example,

    Author:
    Matej Novotny
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String value
      Unique name that qualifies a ManagedExecutor or ThreadContext.
    • Element Detail

      • value

        String value
        Unique name that qualifies a ManagedExecutor or ThreadContext.
        Returns:
        the name that qualifies a ManagedExecutor or ThreadContext.