@Repeatable(value=ManagedExecutorDefinition.List.class) @Retention(value=RUNTIME) @Target(value=TYPE) public @interface ManagedExecutorDefinition
Defines a ManagedExecutorService
to be 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", context = "java:module/concurrent/MyExecutorContext", hungTaskThreshold = 120000, maxAsync = 5) @ContextServiceDefinition( name = "java:module/concurrent/MyExecutorContext", propagated = { SECURITY, APPLICATION }) public class MyServlet extends HttpServlet { @Resource(lookup = "java:module/concurrent/MyExecutor", name = "java:module/concurrent/env/MyExecutorRef") ManagedExecutorService myExecutor;
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.Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
name
JNDI name of the
ManagedExecutorService instance. |
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
context
The name of a
ContextService instance which
determines how context is applied to tasks and actions that
run on this executor. |
long |
hungTaskThreshold
The amount of time in milliseconds that a task or action
can execute before it is considered hung.
|
int |
maxAsync
Upper bound on contextual tasks and actions that this executor
will simultaneously execute asynchronously.
|
public abstract java.lang.String name
ManagedExecutorService
instance.
The JNDI name must be in a valid Jakarta EE namespace,
such as,
ManagedExecutorService
JNDI name.public abstract java.lang.String context
ContextService
instance which
determines how context is applied to tasks and actions that
run on this executor.
The name can be the name of a ContextServiceDefinition
or
the name of a context-service
deployment descriptor element
or the JNDI name of the Jakarta EE default ContextService
instance, java:comp/DefaultContextService
.
The name of the ContextService
must be no more granular
than the name of this ManagedExecutorDefinition
. For example,
if this ManagedExecutorDefinition
has a name in java:app
,
the ContextService
can be in java:app
or java:global
,
but not in java:module
which would be ambiguous as to which
module's ContextService
definition should be used.
The default value, java:comp/DefaultContextService
, is the
JNDI name of the Jakarta EE default ContextService
.
ContextService
for
capturing and propagating or clearing context.public abstract long hungTaskThreshold
The amount of time in milliseconds that a task or action can execute before it is considered hung.
The default value of -1
indicates unlimited.
public abstract 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.
The default value of -1
indicates unbounded,
although still subject to resource constraints of the system.