Skip to content

Commit

Permalink
ArC: initial documentation for CDI pitfalls with reactive programming
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed May 14, 2024
1 parent 74210f6 commit a56d55f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/src/main/asciidoc/cdi-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,46 @@ public class NoopAsyncObserverExceptionHandler implements AsyncObserverException
}
----

[[reactive_pitfalls]]
== CDI Pitfalls with Reactive Programming

CDI is a purely synchronous framework.
Its notion of asynchrony is very limited and based solely on thread pools and thread offloading.
Therefore, there is a number of pitfalls when using CDI together with reactive programming.

=== Detecting when blocking is allowed

The `BlockingOperationControl.isBlockingAllowed()` method allows detecting when blocking is allowed.
When it is not, and you need to perform a blocking operation, you have to offload it to another thread.
The easiest way is to use the `Vertx.executeBlocking()` method:

[source,java]
----
import io.quarkus.runtime.BlockingOperationControl;
@ApplicationScoped
public class MyBean {
@Inject
Vertx vertx;
@PostConstruct
void init() {
if (BlockingOperationControl.isBlockingAllowed()) {
somethingThatBlocks();
} else {
vertx.executeBlocking(() -> {
somethingThatBlocks();
return null;
});
}
}
void somethingThatBlocks() {
...
}
}
----

[[build_time_apis]]
== Build Time Extensions

Expand Down

0 comments on commit a56d55f

Please sign in to comment.