+

Search Tips   |   Advanced Search

Configure ManagedExecutorService instances

You can configure ManagedExecutorService instances to run asynchronous tasks with the specified thread context. It is a best practice for Java EE applications to avoid directly managing their own threads; therefore, the ManagedExecutorService extends the JSE ExecutorService to provide a way to launch asynchronous tasks within an application server environment. You might also configure the ManagedExecutorService to propagate various thread contexts that are relevant to Java EE applications to the thread of the asynchronous task.

The ManagedExecutorService is available under the <concurrent-1.0> feature and enabled in server.xml as follows:

<featureManager>
 <feature>concurrent-1.0</feature>
</featureManager>

Propagation of context to the thread of a task that is executed by the ManagedExecutorService is managed by the context service. A default instance of the context service (DefaultContextService) is created by the server and configured to propagate at least classloaderContext, jeeMetadataContext and securityContext. This default context service instance is used if a ManagedExecutorService is created without referring to a specific context service instance or configuring a context service instance directly within. Refer to the Configuring thread context service instances topic for more information.

A default managed executor instance (DefaultManagedExecutorService) is available as java:comp/DefaultManagedExecutorService and uses the default context service instance for thread context capture and propagation.

Attention: A current limitation in the Alpha is that submitted tasks might not run until Future.get is invoked.

Example configuration in server.xml:


Example

Managed executor serviced instances can be injected into application components (using @Resource) or looked up with resource environment references (resource-env-ref). Regardless of how the instance is obtained, we can use it interchangeably as javax.enterprise.concurrent.ManagedExecutorService or its java.util.concurrent.ExecutorSerivce superclass.


Parent topic: Administer the Liberty profile manually