Annotation Interface ManagedThreadFactoryDefinition


@Repeatable(List.class) @Retention(RUNTIME) @Target(TYPE) public @interface ManagedThreadFactoryDefinition

Defines a ManagedThreadFactory to be 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",
     context = "java:global/concurrent/MyThreadFactoryContext",
     priority = 4)
 @ContextServiceDefinition(
     name = "java:global/concurrent/MyThreadFactoryContext",
     propagated = APPLICATION)
  public class MyServlet extends HttpServlet {
    @Resource(lookup = "java:global/concurrent/MyThreadFactory",
               name = "java:module/concurrent/env/MyThreadFactoryRef")
     ManagedThreadFactory myThreadFactory;
 

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

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Enables multiple ManagedThreadFactoryDefinition annotations on the same type.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    JNDI name of the ManagedThreadFactory instance.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Determines how context is applied to threads from this thread factory.
    int
    Priority for threads created by this thread factory.
  • Element Details

    • name

      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:
      ManagedThreadFactory JNDI name.
    • context

      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:
      instructions for capturing and propagating or clearing context.
      Default:
      "java:comp/DefaultContextService"
    • priority

      int priority

      Priority for threads created by this thread factory.

      The default is Thread.NORM_PRIORITY.

      Returns:
      the priority for new threads.
      Default:
      5