Skip to content

Commit

Permalink
Docs: duplicated context - minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba authored and holly-cummins committed Jul 13, 2023
1 parent 5a08185 commit 2f01294
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions docs/src/main/asciidoc/duplicated-context.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<String> invoke() {
Context context = Vertx.currentContext();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f01294

Please sign in to comment.