MicroProfile® Context Propagation 1.0

Release Date
Deliverables

MicroProfile Context Propagation includes two core API interfaces.

  • ManagedExecutor - an ExecutorService which runs tasks under the context of the submitting thread (like the Java EE/Jakarta EE ManagedExecutorService) and creates managed CompletableFutures which are backed by the ManagedExecutor and where all dependent actions run under the context of the thread that creates the dependent stage.
  • ThreadContext - a utility that wraps context around core functional interfaces (such as Function, Supplier, Runnable) which can be used in combination any CompletableFuture, to ensure that actions run with context that is captured from the thread which requests the contextualization.

Both of the above provide a fluent builder pattern for the configuration and creation of new instances, allowing the user to more granularly customize how thread context propagation and clearing is done.

MicroProfile Context Propagation also includes an SPI for third-party implementations to plug-in custom providers of thread context, which are then cleared, captured, propagated and restored according to the standard contract defined by ManagedExecutor and ThreadContext for context propagation and clearing.

Compatibility

This is the initial release of MicroProfile Context Propagation.

MicroProfile Context Propagation is designed for full compatibility with (although currently no direct dependencies on) Concurrency Utilitities for Java EE / Jakarta Concurrency.

Themes

CompletionStages that run with predictable thread context

MicroProfile Context Propagation extends the concept of the Java EE/Jakarta EE ManagedExecutorService (absent any direct dependency) with the ability to create CompletableFutures that are backed by the managed executor, such that all dependent stage actions, whether asynchronous or inline, run under thread context that is captured from the thread which creates the dependent stage.

Fine-grained contextualization for specific CompletionStage actions

MicroProfile Context Propagation refines the concept of the Java EE/Jakarta EE ContextService (absent any direct dependency) to optimize and provide a more usable mechanism for granular control over the contextualization of specific CompletionStage actions. This makes it possible to have deterministic and reliable thread context for new dependent stage actions, even when using a standard CompletionStage/CompletableFuture which otherwise lacks thread context awareness.

Make thread context propagation the domain of the application, rather than server configuration

It is the application which knows how it intends to use contextualized tasks and actions and which types of thread context are truly needed. Therefore, the application should have the means to configure how/whether thread context propagation is performed. MicroProfile Context Propagation achieves this with a fluent builder pattern for ManagedExecutor and ThreadContext, and enables the life cycle operations for ManagedExecutors that are created in this manner.

Any third-party which provides thread context should be able to participate in context propagation

MicroProfile Context Propagation externalizes a standard SPI by which third-party implementations which define their own thread context can register and plug in to the thread context propagation model. The application can then leverage context clearing/capture/propagation/restore for these custom context types via MicroProfile Context Propagation, the same as they would leverage spec-defined types of thread context.