-
Notifications
You must be signed in to change notification settings - Fork 40.7k
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
Document virtual threads limitations #38883
Comments
Please track spring-projects/spring-framework#31212 for that enhancement. |
I feel like we have to be quite careful with the Spring Boot documentation so that it doesn't sprawl and attempt to cover every possible situation that can occur. This is especially true for new JDK features where the landscape is still shifting as folks adapt to the feature. Whilst I'm not against adding some general warning, I think "highlight this feature in red and warn other developers about possible problems" is probably going a bit far. I think the ideal situation would be for us to link to something like https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html and leave others to document the limitations. |
I agree with your opinion. |
Good afternoon.
I'd like to discuss the potential issue of enabling virtual threads at the platform level. I would update spring's documentation to use virtual threads. I would highlight this feature in red and warn other developers about possible problems. Virtual threads can be a very big problem if used incorrectly.
spring.threads.virtual.enabled: true
- creates a strong temptation to install immediately and everywhere.This property makes us think that the entire spring will work correctly with virtual threads. But this is definitely not the case.
Let's say I want to use
spring-boot-starter-mail
... I start sending a message in a virtual thread.So what do I see? If I check the application with Flight Recorder I see a lot of
jdk.VirtualThreadPinned
events. If you look at the source code, this is an anti-pattern for virtual threads. There issynchronized
inside and data is sent via the socket inside.I sent messages 3 times and received 59 VirtualThreadPinned. Subject to triggering 20 ms, pinned time was from 100 to 900 ms...
Due to such limitations of virtual threads, you need to be extremely careful when using. Otherwise it can be fatal for the application.
Quote from Quarkus:
See more details here
Before introducing virtual threads, you need to check the entire application in detail. The current state of java projects does not allow them to be used thoughtlessly. Not even all JDK classes can handle virtual threads - look at the class
jdk.internal.misc.Blocker
.I see a lot of advertisements for virtual threads... Some may think that this is the solution to their problems. But virtual threads can be a problem. We need to talk about possible problems at every step.
Spring lacks the ability to fine-tune launch control in virtual threads. For example, you can enter an annotation like Quarkus -
@RunOnVirtualThread
. And it is also possible to add an annotation by analogy@ThreadSafe, @NotThreadSafe
-@VirtualThreadSafe, @NotVirtualThreadSafe
. In terms of severity I would equate it to thread safety.The current java world is not fully prepared for virtual threads. They can create many more problems. But excessive advertising only makes the situation worse.
It is necessary to update the documentation and warn users very strongly about the risks that they can create for themselves and their systems.
P.S. I can pay a lot of attention to this. I can pay a lot of attention to this, but I'm worried about this new and dangerous opportunity. It should be used very carefully
The text was updated successfully, but these errors were encountered: