Annotation 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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
Enables multipleManagedScheduledExecutorDefinition
annotations on the same type. -
Required Element Summary
Modifier and TypeRequired ElementDescriptionJNDI name of theManagedScheduledExecutorService
instance. -
Optional Element Summary
Modifier and TypeOptional ElementDescriptionThe name of aContextService
instance which determines how context is applied to tasks and actions that run on this executor.long
The amount of time in milliseconds that a task or action can execute before it is considered hung.int
Upper bound on contextual tasks and actions that this executor will simultaneously execute asynchronously.Class<?>[]
List of requiredqualifier annotations
.boolean
Indicates whether this executor is requested to create virtualthreads
for tasks that do not run inline.
-
Element Details
-
name
String nameJNDI name of theManagedScheduledExecutorService
instance. The JNDI name must be in a valid Jakarta EE namespace, such as,- java:comp
- java:module
- java:app
- java:global
- Returns:
ManagedScheduledExecutorService
JNDI name.
-
qualifiers
Class<?>[] qualifiersList of required
qualifier annotations
.A
ManagedScheduledExecutorService
injection point with these qualifier annotations injects a bean that is produced by thisManagedScheduledExecutorDefinition
.The default value is an empty list, indicating that this
ManagedScheduledExecutorDefinition
does not automatically produce bean instances for any injection points.When the qualifiers list is non-empty, the container creates a
ManagedScheduledExecutorService
instance and registers anApplicationScoped
bean for it with the specified required qualifiers and required type ofManagedScheduledExecutorService
. 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:global
name
if also configuring a non-empty list of qualifiers.Applications can define their own
Producers
forManagedScheduledExecutorService
injection points as long as the qualifier annotations on the producer do not conflict with the non-emptyqualifiers()
list of aManagedScheduledExecutorDefinition
.- Returns:
- list of qualifiers.
- Since:
- 3.1
- Default:
{}
-
context
String contextThe name of aContextService
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 acontext-service
deployment descriptor element or the JNDI name of the Jakarta EE defaultContextService
instance,java:comp/DefaultContextService
.The name of the
ContextService
must be no more granular than the name of thisManagedScheduledExecutorDefinition
. For example, if thisManagedScheduledExecutorDefinition
has a name injava:app
, theContextService
can be injava:app
orjava:global
, but not injava:module
which would be ambiguous as to which module'sContextService
definition should be used.The default value,
java:comp/DefaultContextService
, is the JNDI name of the Jakarta EE defaultContextService
.- Returns:
- name of the
ContextService
for capturing and propagating or clearing context.
- Default:
"java:comp/DefaultContextService"
-
hungTaskThreshold
long hungTaskThresholdThe amount of time in milliseconds that a task or action can execute before it is considered hung.
The default value of
-1
indicates unlimited.- Returns:
- number of milliseconds after which a task or action is considered hung.
- Default:
-1L
-
maxAsync
int maxAsyncUpper 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 orAsynchronous.runAt()
.The default value of
-1
indicates unbounded, although still subject to resource constraints of the system.- Returns:
- upper limit on asynchronous execution.
- Default:
-1
-
virtual
boolean virtualIndicates whether this executor is requested to create virtual
threads
for tasks that do not run inline. Virtual threads are discussed in theThread
JavaDoc 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
true
value behaves the same as thefalse
value and results in platform threads being created rather than virtual threads.- Returns:
true
if the executor can create virtual threads, otherwisefalse
.- Since:
- 3.1
- Default:
false
-