Annotation Type ManagedThreadFactoryDefinition
-
@Repeatable(List.class) @Retention(RUNTIME) @Target(TYPE) public @interface ManagedThreadFactoryDefinition
Defines
ManagedThreadFactoryinstances to be injected intoManagedThreadFactoryinjection 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,@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 aManagedThreadFactorywith 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 amanaged-thread-factoryandManagedThreadFactoryDefinitionhave the same name, their attributes are merged to define a singleManagedThreadFactorydefinition, with each attribute that is specified in themanaged-thread-factorydeployment 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 theManagedThreadFactoryinstance.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.StringcontextDetermines how context is applied to threads from this thread factory.intpriorityPriority for platform threads created by this thread factory.java.lang.Class<?>[]qualifiersList of requiredqualifier annotations.booleanvirtualIndicates whether this thread factory is requested to create virtualthreads.
-
-
-
Element Detail
-
name
java.lang.String name
JNDI name of theManagedThreadFactoryinstance. The JNDI name must be in a valid Jakarta EE namespace, such as,- java:comp
- java:module
- java:app
- java:global
- Returns:
ManagedThreadFactoryJNDI name.
-
-
-
qualifiers
java.lang.Class<?>[] qualifiers
List of required
qualifier annotations.A
ManagedThreadFactoryinjection point with these qualifier annotations injects a bean that is produced by thisManagedThreadFactoryDefinition.The default value is an empty list, indicating that this
ManagedThreadFactoryDefinitiondoes not automatically produce bean instances for any injection points.When the qualifiers list is non-empty, the container creates a
ManagedThreadFactoryinstance and registers anApplicationScopedbean for it with the specified required qualifiers and required type ofManagedThreadFactory. 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
ProducersforManagedThreadFactoryinjection 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
java.lang.String context
Determines how context is applied to threads from this thread factory.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 thisManagedThreadFactoryDefinition. For example, if thisManagedThreadFactoryDefinitionhas 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:
- instructions for capturing and propagating or clearing context.
- Default:
- "java:comp/DefaultContextService"
-
-
-
virtual
boolean virtual
Indicates whether this thread factory is requested to create virtual
threads. Virtual threads are discussed in theThreadJavaDoc under the section that is titled 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.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 thread factory is requested to create virtual threads, otherwisefalse.- Since:
- 3.1
- Default:
- false
-
-