javax.enterprise.concurrent

Interface ManagedThreadFactory

  • All Superinterfaces:
    ThreadFactory

    public interface ManagedThreadFactory
    extends ThreadFactory
    A manageable version of a ThreadFactory.

    A ManagedThreadFactory extends the Java™ SE ThreadFactory to provide a method for creating threads for execution in a Java™ EE environment. Implementations of the ManagedThreadFactory are provided by a Java™ EE Product Provider. Application Component Providers use the Java Naming and Directory Interface™ (JNDI) to look-up instances of one or more ManagedThreadFactory objects using resource environment references.

    The Concurrency Utilities for Java™ EE specification describes several behaviors that a ManagedThreadFactory can implement. The Application Component Provider and Deployer identify these requirements and map the resource environment reference appropriately.

    Threads returned from the newThread() method should implement the ManageableThread interface. The Runnable task that is allocated to the new thread using the ThreadFactory.newThread(Runnable) method will run with the application component context of the component instance that created (looked-up) this ManagedThreadFactory instance.

    The task runs without an explicit transaction (they do not enlist in the application component's transaction). If a transaction is required, use a javax.transaction.UserTransaction instance. A UserTransaction instance is available in JNDI using the name: "java:comp/UserTransaction"

    Example:

     public run() {
       // Begin of task
       InitialContext ctx = new InitialContext();
       UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
       ut.begin();
    
       // Perform transactional business logic
    
       ut.commit();
     }
    A ManagedThreadFactory can be used with Java SE ExecutorService implementations directly.

    Example:

     /**
     * Create a ThreadPoolExecutor using a ManagedThreadFactory.
     * Resource Mappings:
     *  type:      javax.enterprise.concurrent.ManagedThreadFactory
     *  jndi-name: concurrent/tf/DefaultThreadFactory
     */
    
     @Resource(name="concurrent/tf/DefaultThreadFactory")
     ManagedThreadFactory tf;
     
     public ExecutorService getManagedThreadPool() {
    
       // All threads will run as part of this application component.
       return new ThreadPoolExecutor(5, 10, 5, TimeUnit.SECONDS,
           new ArrayBlockingQueue<Runnable>(10), tf);
     }
     

    Since:
    1.0
    • Method Summary

      • Methods inherited from interface java.util.concurrent.ThreadFactory

        newThread

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

21/08/2025 17:18:02 Cette version de la page est en cache (à la date du 21/08/2025 17:18:02) afin d'accélérer le traitement.
Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.

Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/enterprise/concurrent/ManagedThreadFactory.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com, ManagedThreadFactory (Java(TM) EE 7 Specification APIs)

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.