+

Search Tips   |   Advanced Search

Configure thread context service instances

We can configure ContextService instances to capture a managed thread context and apply it to invocations of specified interface methods on any thread.

It is a best practice for Java EE applications to avoid directly managing their own threads; therefore, the ContextService provides a way to establish a previously captured thread context onto unmanaged threads, as well as managed threads, overlaying any thread context that is in place.

Enable the thread context service in server.xml. The thread context service is available under the <concurrent-1.0> feature.

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


Results

A default thread context service instance (DefaultContextService) is created by the server and configured to capture and propagate at least classloaderContext, jeeMetadataContext and securityContext. We can configure thread context propagation to include the following types of thread context:

classloaderContext

Makes the thread context classloader of the submitter of the task available to the task.

If the context classloader is serialized, the classloader must be a thread context classloader from the application. Classloader serialization for Web Application Bundles is not currently supported.

jeeMetadataContext

Makes the namespace of the application component that submitted the task available to the task.

securityContext

We must enable the appSecurity-2.0 feature in server.xml to use this type of thread context. Makes the caller subject and invocation subject of the submitter of the task available to the task, and this is accomplished by logging in with the submitter's WSPrincipal using JAAS login. For details on what information in the submitter's subject is not in the security context, see the concurrent-1.0 feature restrictions.

Important: Additional thread context providers might be made available by features in stack products. The optional baseContextRef attribute allows a context service instance to inherit from the context configuration of another context service instance.


Example

Inject thread context service instances into application components (using @Resource) or look up with resource environment references (resource-env-ref).


Parent topic: Administer the Liberty profile manually