-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot inform ArC to instantiate bean in worker thread #40418
Comments
CDI/ArC creates beans, by design, on the current thread. The CDI API ( A good mitigation strategy is to initialize the beans eagerly (if possible), for example an If you really need to execute some blocking code in your bean, in import io.quarkus.runtime.BlockingOperationControl;
@RequestScoped
public class MyBean {
@Inject
Vertx vertx;
@PostConstruct
void init() {
if (BlockingOperationControl.isBlockingAllowed()) {
somethingThatBlocks();
} else {
vertx.executeBlocking(() -> {
// note that request context is not activated here
somethingThatBlocks();
return null;
});
}
}
void somethingThatBlocks() {}
} And of course, it gets more complicated if you need to synchronize the state, i.e. if the blocking operation initializes some state of the bean. |
Eager initialization works for one of my uses. For my other uses, I have used the BlockingOperationControl check. |
Consider adding this to documentation somewhere? |
Totally makes sense! |
+1 |
Describe the bug
HttpAuthenticator is instantiated in io thread. I cannot figure out where to use a
@Blocking
annotation to inform ArC to run on worker thread.Expected behavior
ArC creates beans in worker thread or ability to annotate injection points so that ArC will inject in worker thread.
Actual behavior
Bean is instantiated in io thread
How to Reproduce?
No response
Output of
uname -a
orver
Darwin YGDMXD4XYJ 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64
Output of
java -version
openjdk version "17.0.6" 2023-01-17 LTS OpenJDK Runtime Environment Zulu17.40+19-CA (build 17.0.6+10-LTS) OpenJDK 64-Bit Server VM Zulu17.40+19-CA (build 17.0.6+10-LTS, mixed mode, sharing)
Quarkus version or git rev
3.10.0
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.9.5
Additional information
No response
The text was updated successfully, but these errors were encountered: