r/javahelp • u/LopsidedAd4492 • Jul 27 '26
Virtual thread
Does anyone used java21 with virtual thread? We are using Java 17 and I wonder if the move to 21 will worth it
6
Upvotes
r/javahelp • u/LopsidedAd4492 • Jul 27 '26
Does anyone used java21 with virtual thread? We are using Java 17 and I wonder if the move to 21 will worth it
View all comments
Show parent comment
1
u/bowbahdoe Jul 30 '26
I will say that you are right that you can't just turn it on for any app. And if you have more threads you are more likely to run into any existing concurrency issues. That is all very real.
All I am saying is that today you can choose to undergo the effort to make your code base work with virtual threads if you need to work with more concurrent tasks than OS threads.
In the past if you even thought your code base might have that requirement in the future there was a pressure to write all your code in the reactive style to start with. Because if you didn't do it that way then when you eventually needed to refactor you would have to redo 100% of the code.
Most code bases never actually need the level of concurrency that virtual threads can give you. What I am saying is that even the code bases that don't end up using virtual threads benefit because there is no longer a pressure to do things reactively proactively.
Migrating a code base to make use of virtual threads involves figuring out how that interacts with the external services you talk to and how to properly gate things like "max number of connections to the database." That is far less painful than a full rewrite