Annotation Type ManagedScheduledExecutorDefinition
-
@Repeatable(List.class) @Retention(RUNTIME) @Target(TYPE) public @interface ManagedScheduledExecutorDefinition
Defines a
ManagedScheduledExecutorServiceto be registered in JNDI by the container under the JNDI name that is specified in thename()attribute.Application components can refer to this JNDI name in the
lookupattribute of aResourceannotation,@ManagedScheduledExecutorDefinition( name = "java:comp/concurrent/MyScheduledExecutor", context = "java:comp/concurrent/MyScheduledExecutorContext", hungTaskThreshold = 30000, maxAsync = 3) @ContextServiceDefinition( name = "java:comp/concurrent/MyScheduledExecutorContext", propagated = APPLICATION) public class MyServlet extends HttpServlet { @Resource(lookup = "java:comp/concurrent/MyScheduledExecutor", name = "java:comp/concurrent/env/MyScheduledExecutorRef") ManagedScheduledExecutorService myScheduledExecutor;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 aManagedScheduledExecutorServicewith 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 amanaged-scheduled-executorandManagedScheduledExecutorDefinitionhave the same name, their attributes are merged to define a singleManagedScheduledExecutorServicedefinition, with each attribute that is specified in themanaged-scheduled-executordeployment descriptor entry taking precedence over the corresponding attribute of the annotation.- Since:
- 3.0
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description StringnameJNDI name of theManagedScheduledExecutorServiceinstance.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description StringcontextThe name of aContextServiceinstance which determines how context is applied to tasks and actions that run on this executor.longhungTaskThresholdThe amount of time in milliseconds that a task or action can execute before it is considered hung.intmaxAsyncUpper bound on contextual tasks and actions that this executor will simultaneously execute asynchronously.
-
-
-
Element Detail
-
name
String name
JNDI name of theManagedScheduledExecutorServiceinstance. The JNDI name must be in a valid Jakarta EE namespace, such as,- java:comp
- java:module
- java:app
- java:global
- Returns:
ManagedScheduledExecutorServiceJNDI name.
-
-
-
context
String context
The name of aContextServiceinstance which determines how context is applied to tasks and actions that run on this executor.The name can be the name of a
ContextServiceDefinitionor the name of acontext-servicedeployment descriptor element or the JNDI name of the Jakarta EE defaultContextServiceinstance,java:comp/DefaultContextService.The name of the
ContextServicemust be no more granular than the name of thisManagedScheduledExecutorDefinition. For example, if thisManagedScheduledExecutorDefinitionhas a name injava:app, theContextServicecan be injava:apporjava:global, but not injava:modulewhich would be ambiguous as to which module'sContextServicedefinition should be used.The default value,
java:comp/DefaultContextService, is the JNDI name of the Jakarta EE defaultContextService.- Returns:
- name of the
ContextServicefor capturing and propagating or clearing context.
- Default:
- "java:comp/DefaultContextService"
-
-
-
maxAsync
int maxAsync
Upper bound on contextual tasks and actions that this executor will simultaneously execute asynchronously. This constraint does not apply to tasks and actions that the executor runs inline, such as when a thread requests
CompletableFuture.join()and the action runs inline if it has not yet started. This constraint also does not apply to tasks that are scheduled via theschedule*methods.The default value of
-1indicates unbounded, although still subject to resource constraints of the system.- Returns:
- upper limit on asynchronous execution.
- Default:
- -1
-
-