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
jakarta. 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.
| Modifier and Type | Class and Description |
|---|---|
| public static @interface | ManagedExecutorDefinition.
Enables multiple |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: name of theContextService for
capturing and propagating or clearing context.The name of a |
| public long | Returns: number of milliseconds after which a task or action is considered hung.The amount of time in milliseconds that a task or action can execute before it is considered hung. |
| public int | Returns: upper limit on asynchronous execution.Upper bound on contextual tasks and actions that this executor will simultaneously execute asynchronously. |
| public String | |
| public Class | |
| public boolean |
| context | back to summary |
|---|---|
| public String context() The name of a
The name can be the name of a
The name of the
The default value,
| |
| hungTaskThreshold | back to summary |
|---|---|
| public long hungTaskThreshold() The amount of time in milliseconds that a task or action can execute before it is considered hung. The default value of
| |
| maxAsync | back to summary |
|---|---|
| public 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
The default value of
| |
| name | back to summary |
|---|---|
| public String name() JNDI name of the
| |
| qualifiers | back to summary |
|---|---|
| public Class List of required A The default value is an empty list, indicating that this
When the qualifiers list is non-empty, the container creates
a Applications can define their own
| |
| virtual | back to summary |
|---|---|
| public boolean virtual() Indicates whether this executor is requested to
create virtual When The default is 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
| |
ManagedExecutorDefinition
annotations on the same type.
| Modifier and Type | Method and Description |
|---|---|
| public ManagedExecutorDefinition[] |
| value | back to summary |
|---|---|
| public ManagedExecutorDefinition[] value() | |