-
- All Superinterfaces:
- ThreadFactory
public interface ManagedThreadFactory extends ThreadFactory
A manageable version of aThreadFactory
.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 theManageableThread
interface. The Runnable task that is allocated to the new thread using theThreadFactory.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
-
-
Document created the 11/06/2005, last modified the 18/08/2025
Source of the printed document:https://www.gaudry.be/en/java-api-javaee-rf-javax/enterprise/concurrent/managedthreadfactory.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.