Annotation Type ManagedExecutorDefinition
-
@Repeatable(List.class) @Retention(RUNTIME) @Target(TYPE) public @interface ManagedExecutorDefinition
Defines a
ManagedExecutorServiceto be injected intoManagedExecutorServiceinjection points including any requiredQualifierannotations specified byqualifiers()and 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,@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 aManagedExecutorServicewith 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 amanaged-executorandManagedExecutorDefinitionhave the same name, their attributes are merged to define a singleManagedExecutorServicedefinition, with each attribute that is specified in themanaged-executordeployment 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
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.StringnameJNDI name of theManagedExecutorServiceinstance.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.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.java.lang.Class<?>[]qualifiersList of requiredqualifier annotations.booleanvirtualIndicates whether this executor is requested to create virtualthreadsfor tasks that do not run inline.
-
-
-
Element Detail
-
name
java.lang.String name
JNDI name of theManagedExecutorServiceinstance. The JNDI name must be in a valid Jakarta EE namespace, such as,- java:comp
- java:module
- java:app
- java:global
- Returns:
ManagedExecutorServiceJNDI name.
-
-
-
qualifiers
java.lang.Class<?>[] qualifiers
List of required
qualifier annotations.A
ManagedExecutorServiceinjection point with these qualifier annotations injects a bean that is produced by thisManagedExecutorDefinition.The default value is an empty list, indicating that this
ManagedExecutorDefinitiondoes not automatically produce bean instances for any injection points.When the qualifiers list is non-empty, the container creates a
ManagedExecutorServiceinstance and registers anApplicationScopedbean for it with the specified required qualifiers and required type ofManagedExecutorService. The life cycle of the bean aligns with the life cycle of the application and the bean is not accessible from outside of the application. Applications must not configure ajava:globalnameif also configuring a non-empty list of qualifiers.Applications can define their own
ProducersforManagedExecutorServiceinjection points as long as the qualifier annotations on the producer do not conflict with the non-emptyqualifiers()list of aManagedExecutorDefinition.- Returns:
- list of qualifiers.
- Since:
- 3.1
- Default:
- {}
-
-
-
context
java.lang.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 thisManagedExecutorDefinition. For example, if thisManagedExecutorDefinitionhas 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 does not apply to tasks that are scheduled viaAsynchronous.runAt().The default value of
-1indicates unbounded, although still subject to resource constraints of the system.- Returns:
- upper limit on asynchronous execution.
- Default:
- -1
-
-
-
virtual
boolean virtual
Indicates whether this executor is requested to create virtual
threadsfor tasks that do not run inline. Virtual threads are discussed in theThreadJavaDoc under the section that is titled Virtual threads.When
true, the executor can create virtual threads if it is capable of doing so and if the request is not overridden by vendor-specific configuration that restricts the use of virtual threads.The default is
false, indicating that the executor must not create virtual threads.It should be noted that some tasks, such as completion stage actions, can run inline on an existing thread in response to events such as the completion of another stage or a join operation on the completion stage. In situations such as these, the executor does not control the type of thread that is used to run the task.
When running on Java SE 17, the
truevalue behaves the same as thefalsevalue and results in platform threads being created rather than virtual threads.- Returns:
trueif the executor can create virtual threads, otherwisefalse.- Since:
- 3.1
- Default:
- false
-
-