File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -1069,6 +1069,47 @@ public class NoopAsyncObserverExceptionHandler implements AsyncObserverException
1069
1069
}
1070
1070
----
1071
1071
1072
+ [[reactive_pitfalls]]
1073
+ == Pitfalls with Reactive Programming
1074
+
1075
+ CDI is a purely synchronous framework.
1076
+ Its notion of asynchrony is very limited and based solely on thread pools and thread offloading.
1077
+ Therefore, there is a number of pitfalls when using CDI together with reactive programming.
1078
+
1079
+ === Detecting When Blocking Is Allowed
1080
+
1081
+ The `io.quarkus.runtime.BlockingOperationControl#isBlockingAllowed()` method can be used to detect whether blocking is allowed on the current thread.
1082
+ When it is not, and you need to perform a blocking operation, you have to offload it to another thread.
1083
+ The easiest way is to use the `Vertx.executeBlocking()` method:
1084
+
1085
+ [source,java]
1086
+ ----
1087
+ import io.quarkus.runtime.BlockingOperationControl;
1088
+
1089
+ @ApplicationScoped
1090
+ public class MyBean {
1091
+ @Inject
1092
+ Vertx vertx;
1093
+
1094
+ @PostConstruct
1095
+ void init() {
1096
+ if (BlockingOperationControl.isBlockingAllowed()) {
1097
+ somethingThatBlocks();
1098
+ } else {
1099
+ vertx.executeBlocking(() -> {
1100
+ somethingThatBlocks();
1101
+ return null;
1102
+ });
1103
+ }
1104
+ }
1105
+
1106
+ void somethingThatBlocks() {
1107
+ // use the file system or JDBC, call a REST service, etc.
1108
+ Thread.sleep(5000);
1109
+ }
1110
+ }
1111
+ ----
1112
+
1072
1113
[[build_time_apis]]
1073
1114
== Build Time Extensions
1074
1115
You can’t perform that action at this time.
0 commit comments