Annotation Interface ManagedScheduledExecutorDefinition


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

Defines a ManagedScheduledExecutorService to be injected into ManagedScheduledExecutorService 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,

 @ManagedScheduledExecutorDefinition(
     name = "java:comp/concurrent/MyScheduledExecutor",
     qualifiers = MyQualifier.class,
     context = "java:comp/concurrent/MyScheduledExecutorContext",
     hungTaskThreshold = 30000,
     maxAsync = 3)
 @ContextServiceDefinition(
     name = "java:comp/concurrent/MyScheduledExecutorContext",
     propagated = APPLICATION)
 public class MyServlet extends HttpServlet {
     @Inject
     @MyQualifier
     ManagedScheduledExecutorService myScheduledExecutor1;

     @Resource(lookup = "java:comp/concurrent/MyScheduledExecutor",
               name = "java:comp/concurrent/env/MyScheduledExecutorRef")
     ManagedScheduledExecutorService myScheduledExecutor2;
     ...

 @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:comp/env/concurrent/MyScheduledExecutorRef</resource-env-ref-name>
    <resource-env-ref-type>jakarta.enterprise.concurrent.ManagedScheduledExecutorService</resource-env-ref-type>
    <lookup-name>java:comp/concurrent/MyScheduledExecutor</lookup-name>
 </resource-env-ref>
 
You can also define a ManagedScheduledExecutorService with the <managed-scheduled-executor> deployment descriptor element. For example,
 <managed-scheduled-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-scheduled-executor>
 
If a managed-scheduled-executor and ManagedScheduledExecutorDefinition have the same name, their attributes are merged to define a single ManagedScheduledExecutorService definition, with each attribute that is specified in the managed-scheduled-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