MicroProfile® Context Propagation 1.0

MicroProfile Context Propagation 1.0 provides APIs for obtaining CompletableFutures that are backed by managed threads (threads that are managed by the container), with the ability to capture context from the thread that creates the CompletableFuture and apply it when running the CompletionStage action.  This enables CompletionStage actions to rely on having predictable thread context and enables users of these CompletionStages to guard against unintentional donation of thread context.

Example of ManagedExecutor, which contextualizes all dependent stages:

ManagedExecutor executor = ManagedExecutor.builder()
.propagated(ThreadContext.CDI, ThreadContext.APPLICATION)
CompletableFuture<Integer> stage = executor

Example of ThreadContext for granular contextualization of a single stage:

ThreadContext threadContext = ThreadContext.builder()
.cleared(ThreadContext.SECURITY, ThreadContext.TRANSACTION)
Function<Integer, Double> getItemCost = threadContext.contextualFunction(id -> {
// java:comp, java:module, java:app lookups require the application's context
DataSource ds = InitialContext.doLookup("java:app/env/jdbc/ds1");
unmanagedStage4 = unmanagedStage1.thenApply(getProductId)

Release Date
Release Type
Major release (API breakage)