Annotation Interface ManagedThreadFactoryDefinition
Defines ManagedThreadFactory
instances
to be injected into
ManagedThreadFactory
injection points
with the specified 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,
@ManagedThreadFactoryDefinition( name = "java:global/concurrent/MyThreadFactory", qualifiers = MyQualifier.class, context = "java:global/concurrent/MyThreadFactoryContext", priority = 4) @ContextServiceDefinition( name = "java:global/concurrent/MyThreadFactoryContext", propagated = APPLICATION) public class MyServlet extends HttpServlet { @Inject @MyQualifier ManagedThreadFactory myThreadFactory1; @Resource(lookup = "java:global/concurrent/MyThreadFactory", name = "java:module/concurrent/env/MyThreadFactoryRef") ManagedThreadFactory myThreadFactory2; ... @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/MyThreadFactoryRef</resource-env-ref-name> <resource-env-ref-type>jakarta.enterprise.concurrent.ManagedThreadFactory</resource-env-ref-type> <lookup-name>java:global/concurrent/MyThreadFactory</lookup-name> </resource-env-ref>You can also define a
ManagedThreadFactory
with the
<managed-thread-factory>
deployment descriptor element.
For example,
<managed-thread-factory> <name>java:global/concurrent/MyThreadFactory</name> <context-service-ref>java:global/concurrent/MyThreadFactoryContext</context-service-ref> <priority>4</priority> </managed-thread-factory>If a
managed-thread-factory
and ManagedThreadFactoryDefinition
have the same name, their attributes are merged to define a single
ManagedThreadFactory
definition, with each attribute that is specified
in the managed-thread-factory
deployment descriptor entry taking
precedence over the corresponding attribute of the annotation.- Since:
- 3.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
Enables multipleManagedThreadFactoryDefinition
annotations on the same type. -
Required Element Summary
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionDetermines how context is applied to threads from this thread factory.int
Priority for threads created by this thread factory.Class<?>[]
List ofinvalid reference
qualifier annotations
boolean
Indicates whether this thread factory is requested to createvirtual
threads.
-
Element Details
-
name
String nameJNDI name of theManagedThreadFactory
instance. The JNDI name must be in a valid Jakarta EE namespace, such as,- java:comp
- java:module
- java:app
- java:global
- Returns:
ManagedThreadFactory
JNDI name.
-
qualifiers
Class<?>[] qualifiersList of
invalid reference
qualifier annotations
A
ManagedThreadFactory
injection point with these qualifier annotations injects a bean that is produced by thisManagedThreadFactoryDefinition
.The default value is an empty list, indicating that this
ManagedThreadFactoryDefinition
does not automatically produce bean instances for any injection points.Applications can define their own
invalid reference
Producers
ManagedThreadFactory
injection points as long as the qualifier annotations on the producer do not conflict with the non-emptyqualifiers()
list of aManagedThreadFactoryDefinition
.- Returns:
- list of qualifiers.
- Since:
- 3.1
- Default:
{}
-
context
String contextDetermines how context is applied to threads from this thread factory.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 thisManagedThreadFactoryDefinition
. For example, if thisManagedThreadFactoryDefinition
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:
- instructions for capturing and propagating or clearing context.
- Default:
"java:comp/DefaultContextService"
-
priority
int priorityPriority for threads created by this thread factory.
The default is
Thread.NORM_PRIORITY
.- Returns:
- the priority for new threads.
- Default:
5
-
virtual
boolean virtualIndicates whether this thread factory is requested to create
virtual
threads.When
true
, the thread factory 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 thread factory must not create virtual threads. Whenfalse
, the thread factory always creates platform threads.- Returns:
true
if the thread factory is requested to create virtual threads, otherwisefalse
.- Since:
- 3.1
- Default:
false
-