diff --git a/docs/src/main/asciidoc/duplicated-context.adoc b/docs/src/main/asciidoc/duplicated-context.adoc index d1e03e48fa751..2ff54e2c9548e 100644 --- a/docs/src/main/asciidoc/duplicated-context.adoc +++ b/docs/src/main/asciidoc/duplicated-context.adoc @@ -19,7 +19,7 @@ When using a reactive and asynchronous execution model, you cannot use the same To avoid using many process threads, and reduce resource usage (and also increase the concurrency of the application), the same thread can be used to handle multiple concurrent processing. Thus, you cannot use `ThreadLocals` as the values would be leaked between the various concurrent processing. -_Duplicated Contexts_ are a construct that provides the same kind of propagation but for asynchronous processing. +Vert.x _duplicated context_ is a construct that provides the same kind of propagation but for asynchronous processing. It can also be used with synchronous code. This document explains duplicated contexts, how to retrieve one, use it, and how it's propagated along the (asynchronous) processing. @@ -76,14 +76,14 @@ In Quarkus, when you execute reactive code, you run in a _Context_, representing @Path("/hello1") public String hello1() { Context context = Vertx.currentContext(); - return "Hello, you are running on context: %s".formatted(context); <1> + return "Hello, you are running on context: %s and on thread %s".formatted(context, Thread.currentThread()); <1> } @GET @Path("/hello2") public String hello2() { // Called on a worker thread (because it has a blocking signature) Context context = Vertx.currentContext(); - return "Hello, you are running on context: %s and on thread %s".formatted(context); <2> + return "Hello, you are running on context: %s and on thread %s".formatted(context, Thread.currentThread()); <2> } ---- <1> Produces: `Hello 1, you are running on context: io.vertx.core.impl.DuplicatedContext@5dc42d4f and on thread Thread[vert.x-eventloop-thread-1,5,main]` - so invoked on an event loop. @@ -126,7 +126,10 @@ The continuation invokes on the same duplicated context, will have access to tha [source, java] ---- +import io.smallrye.common.vertx.ContextLocals; + AtomicInteger counter = new AtomicInteger(); + public Uni invoke() { Context context = Vertx.currentContext(); @@ -190,7 +193,7 @@ It is the case with: - RESTEasy Reactive - gRPC - Reactive Routes -- `@ConsumeEvent` +- Vert.x Event Bus `@ConsumeEvent` - Reactive REST Client - Reactive Messaging (Kafka, AMQP) - Funqy