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,
@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.
| Modifier and Type | Class and Description |
|---|---|
| public static @interface | ManagedThreadFactoryDefinition.
Enables multiple |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: instructions for capturing and propagating or clearing context.Determines how context is applied to threads from this thread factory. |
| public String | |
| public int | Returns: the priority for new threads.Priority for platform threads created by this thread factory. |
| public Class | |
| public boolean |
| context | back to summary |
|---|---|
| public String context() Determines how context is applied to threads from this thread factory.
The name can be the name of a
The name of the
The default value,
| |
| name | back to summary |
|---|---|
| public String name() JNDI name of the
| |
| priority | back to summary |
|---|---|
| public int priority() Priority for platform threads created by this thread factory.
Virtual threads always have the priority The default is
| |
| 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 thread factory is requested to
create virtual When The default is When running on Java SE 17, the
| |
ManagedThreadFactoryDefinition
annotations on the same type.
| Modifier and Type | Method and Description |
|---|---|
| public ManagedThreadFactoryDefinition[] |
| value | back to summary |
|---|---|
| public ManagedThreadFactoryDefinition[] value() | |