Annotation Interface ManagedExecutorDefinition


@Repeatable(ManagedExecutorDefinition.List.class) @Retention(RUNTIME) @Target(TYPE) public @interface ManagedExecutorDefinition

Defines a ManagedExecutorService to be injected into ManagedExecutorService injection points including any required Qualifier annotations specified by qualifiers() and registered in JNDI by the container under the JNDI name that is specified in the name() attribute.

Application components can refer to this JNDI name in the lookup attribute of a Resource annotation,

 @ManagedExecutorDefinition(
     name = "java:module/concurrent/MyExecutor",
     qualifiers = MyQualifier.class,
     context = "java:module/concurrent/MyExecutorContext",
     hungTaskThreshold = 120000,
     maxAsync = 5)
 @ContextServiceDefinition(
     name = "java:module/concurrent/MyExecutorContext",
     propagated = { SECURITY, APPLICATION })
 public class MyServlet extends HttpServlet {
     @Inject
     @MyQualifier
     ManagedExecutorService myExecutor1;

     @Resource(lookup = "java:module/concurrent/MyExecutor",
               name = "java:module/concurrent/env/MyExecutorRef")
     ManagedExecutorService myExecutor2;
     ...

 @Qualifier
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
 public @interface MyQualifier {}
 

Resource environment references in a deployment descriptor can similarly specify the lookup-name,

 <resource-env-ref>
    <resource-env-ref-name>java:module/env/concurrent/MyExecutorRef</resource-env-ref-name>
    <resource-env-ref-type>jakarta.enterprise.concurrent.ManagedExecutorService</resource-env-ref-type>
    <lookup-name>java:module/concurrent/MyExecutor</lookup-name>
 </resource-env-ref>
 
You can also define a ManagedExecutorService with the <managed-executor> deployment descriptor element. For example,
 <managed-executor>
    <name>java:module/concurrent/MyExecutor</name>
    <context-service-ref>java:module/concurrent/MyExecutorContext</context-service-ref>
    <hung-task-threshold>120000</hung-task-threshold>
    <max-async>5</max-async>
 </managed-executor>
 
If a managed-executor and ManagedExecutorDefinition have the same name, their attributes are merged to define a single ManagedExecutorService definition, with each attribute that is specified in the managed-executor deployment descriptor entry taking precedence over the corresponding attribute of the annotation. If any qualifier elements are specified, the set of qualifier elements replaces the qualifiers attribute of the annotation.
Since:
3.0