Top Description Inners Methods
jakarta.enterprise.concurrent

public @Interface ManagedThreadFactoryDefinition

extends Annotation
Annotations
@Repeatable:List
@Retention:RUNTIME
@Target:TYPE
Static Imports
java.lang.annotation.ElementType.TYPE, .RetentionPolicy.RUNTIME

Defines ManagedThreadFactory instances to be injected into ManagedThreadFactory 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.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. If any qualifier elements are specified, the set of qualifier elements replaces the qualifiers attribute of the annotation.
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
ManagedThreadFactoryDefinition.List

Enables multiple ManagedThreadFactoryDefinition annotations on the same type.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

instructions for capturing and propagating or clearing context.
context
()

Determines how context is applied to threads from this thread factory.

public String

Returns:

ManagedThreadFactory JNDI name.
name
()

JNDI name of the ManagedThreadFactory instance.

public int

Returns:

the priority for new threads.
priority
()

Priority for platform threads created by this thread factory.

public Class<?>[]

Returns:

list of qualifiers.
qualifiers
()

List of required qualifier annotations.

public boolean

Returns:

true if the thread factory is requested to create virtual threads, otherwise false.
virtual
()

Indicates whether this thread factory is requested to create virtual threads.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

contextback to summary
public String context()

Determines how context is applied to threads from this thread factory.

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 ManagedThreadFactoryDefinition. For example, if this ManagedThreadFactoryDefinition 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.

Returns:String

instructions for capturing and propagating or clearing context.

nameback to summary
public String name()

JNDI name of the ManagedThreadFactory instance. The JNDI name must be in a valid Jakarta EE namespace, such as,

  • java:comp
  • java:module
  • java:app
  • java:global
Returns:String

ManagedThreadFactory JNDI name.

priorityback to summary
public int priority()

Priority for platform threads created by this thread factory. Virtual threads always have the priority java.lang.Thread#NORM_PRIORITY regardless of this setting.

The default is java.lang.Thread#NORM_PRIORITY.

Returns:int

the priority for new threads.

qualifiersback to summary
public Class<?>[] qualifiers()

List of required qualifier annotations.

A ManagedThreadFactory injection point with these qualifier annotations injects a bean that is produced by this ManagedThreadFactoryDefinition.

The default value is an empty list, indicating that this ManagedThreadFactoryDefinition does not automatically produce bean instances for any injection points.

When the qualifiers list is non-empty, the container creates a ManagedThreadFactory instance and registers an ApplicationScoped bean for it with the specified required qualifiers and required type of ManagedThreadFactory. 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 a java:global name if also configuring a non-empty list of qualifiers.

Applications can define their own Producers for ManagedThreadFactory injection points as long as the qualifier annotations on the producer do not conflict with the non-empty qualifiers() list of a ManagedThreadFactoryDefinition.

Returns:Class<?>[]

list of qualifiers.

Since
3.1
virtualback to summary
public boolean virtual()

Indicates whether this thread factory is requested to create virtual threads. Virtual threads are discussed in the Thread JavaDoc 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. When false, the thread factory always creates platform threads.

When running on Java SE 17, the true value behaves the same as the false value and results in platform threads being created rather than virtual threads.

Returns:boolean

true if the thread factory is requested to create virtual threads, otherwise false.

Since
3.1
jakarta.enterprise.concurrent back to summary

public @Interface ManagedThreadFactoryDefinition.List

extends Annotation
Annotations
@Retention:RUNTIME
@Target:TYPE

Enables multiple ManagedThreadFactoryDefinition annotations on the same type.

Method Summary

Modifier and TypeMethod and Description
public ManagedThreadFactoryDefinition[]
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public ManagedThreadFactoryDefinition[] value()