Virtual threads
If I have the following implementation
Service
If Async already wraps the method in a CompletableFuture it is recommended not to rewrap it because it would be redundant.
How I implement in the controller, I'm using java 21, version spring 3.5.0
13 Replies
⌛ This post has been reserved for your question.
Hey @pedroavila! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Are you using a recent Spring version? If so, why are you not just enabling virtual threads in the application.properties and do everything synchronously?
version spring 3.5.0 have example the configuration that solved my problem?
Spring Boot 3.5.0 supports virtual threads in the way I mentioned
if you set it in the application.properties, Spring should use virtual threads wherever it can (and where it makes sense)
Is this VirtualThreadConfig implementation no longer necessary?
no
just add
spring.threads.virtual.enabled to the application.properties and it configures everything necessary for virtual threads
which is more than your config class In this magical way I would already be working with virtual threads and my methods would be asynchronous and non-blocking.
The code would be blocking but it doesn't block platform/OS threadsso you don't have the scalability issues/it's as if you'd write asynchronous code
and I would rename the
getAllAsync methodWow, great how wonderful is spring 3+ and java 21 with the virtual threads very magical compared to the traditional threads that you had to configure the thread and work with CompletableFuture, the new implementation is cleaner
yep
Thanks very @dan1st | Daniel
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.
Before your post will be closed, would you like to express your gratitude to any of the people who helped you? When you're done, click I'm done here. Close this post!.Post Closed
This post has been closed by <@558689208907202566>.