The biggest win by far IMHO is a performant alternative for io intensive applications for async frameworks. Not using an async framework tremendously simplifies your code. Code complexity has an enormous projection on everything else, especially when talking on the business level. First and foremost the cost of development and time to market rises. And then comes the cost of maintenance.
Does this mean one doesn’t need to use reactor with spring and can rely on the non-reactive method and still get great performance?
Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
471–480 of 555 posts
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#472Using virtual threads only, can one make a non-blocking UI application? Or do you still need to fall back to Promises or callbacks?
I'm not positive about this but I believe the virtual threads can yield at syscalls (i.e. IO calls). I don't think GUI application code is littered with these syscalls where a virtual thread can naturally yield so you get non-blocking for "free". Someone please correct me if I'm mistaken.
However, something important to remember is that UI frameworks generally require most or all UI interaction to occur on one logical thread. This is because making all the UI code safe for calling from multiple threads would require tons of work, and likely require one massive lock that serializes most ui compontent method calls, or tons of smaller locks. And that is just for the minimum of safety. UI work has tons of implicit state.
User level logic would also likely need additional locking, since even if each method call to a control is thread safe, if you want to perform some kind of conditional action that does not already have some dedicated method, that would pose a problem without some form of synchronization code.
One advantage of the async-await approach in UI scenarios (where continuations always get run on the UI Thread) is that you know that between two awaits, no other code will be running on the UI thread, so can avoid synchronization code. You know if you read a value from a control and then conditional call a method on it, you don't need to worry about racing with another thread. Now whenever an "await" occurs, potentially arbitrary other UI code may have run in the interim, so you may need to reverify the state of things. But this is still much simpler to handle than possibly being preempted at any time, or having another thread literally changing things in parallel.
Green thread based approaches like Virtual Threads do avoid much of the complexity of async-await, but they often do lose those sorts of advantages. Even if the green thread approach has guarantees about the yield points (e.g. only has cooperative yields which only occur when certain specific methods are called), you still lose the ability to locally reason about where those yield points may occur, since any function/method call could potentially call one of those yielding functions, or call something that calls one of them, etc. The only way to regain that info is to "color" the functions again, which was the whole thing peple are trying to avoid with green threads in the first place.
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#473Earlier quoted context omitted.
There are legitimate reasons to chose Go over Java, starting with the build system and the amount of effort needed to produce a single binary. I use Java for 20 years and Go for ~2. I am not actively hating Java but I value my time, specially that was wasted on maven + co.
Maven isn't Java. I've used java for over 20 years and managed to almost completely avoid it. As with npm - I think automatic dependency management at the library level pulls in far too much of the world - most of which your code doesn't actually depend on because the one function you need in lib A, doesn't actually require lib B, and therefore lib B dependencies C&D etc etc etc. Madness. If you do dependency managem…
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#474> Virtual threads offer a more efficient alternative to platform threads, allowing developers to handle a large number of tasks with significantly lower overhead. they should have just called them "Tasks" leaving the already overloaded term "virtual" out of the conversation.
Java's already got tasks[1] within the namespace of parallelism though, but it hasn't overloaded any meaning onto virtual. [1] https://docs.oracle.com/javase/9/docs/api/index.html?javafx/...
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#475Earlier quoted context omitted.
> Those new fancy threads are stored on heap and need to be garbage collected. If you buy into ads and believe that you can create for free millions of threads, then, well, it is not gonna work on production. A typical request easily creates 100's of objects that needs to be garbage collected. Adding a single thread object on top of that means absolutely nothing. And how much garbage to you think reactive frameworks…
How does loom address backpressure?
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#476Earlier quoted context omitted.
Workarounds, and still doesn't fix the issues lacking from the company that owns .NET.
What does the company that owns Java offer? Their Java IDE is https://en.wikipedia.org/wiki/JDeveloper and nobody uses that. The latest release came out in 2019. Everyone is using IntelliJ IDEA or perhaps Eclipse. What does the Python core community offer? IDLE is ugly, is barely an IDE, and didn’t have line numbers until a few years ago. Everyone is using PyCharm or VSCode.
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#477Earlier quoted context omitted.
If you want to return a future you'll need to note that in the return type.
It's not about feature / promise return types. Consider: int someFunc() { doA(); doB(); byte data[] = readFromSocket(); return doC(data); } int callerFunc() { doX(); System.out.println(someFunc()); doY(); } when we invoke the callerFunc() in a virtual thread, it executes till the potentially blocking socket reading, creates a callback or future -like object containing doC(), System.out.println(), doY() - such object…
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#478Earlier quoted context omitted.
If you want to run concurrent io requests, don't you still need to use an async framework and all the fork/join logic? I suppose the slow and naive way is now easier to let limp along as you won't run out of threads?
JVM itself would do async I/O as needed using whatever API the underlying OS provides. Your own I/O code would be straightforward and synchronous. Nothing will run out of threads.
One could argue that automatic promise wrapping and an await keyword ends up giving you cleaner, more simple code (despite the coloring).
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#479The biggest win by far IMHO is a performant alternative for io intensive applications for async frameworks. Not using an async framework tremendously simplifies your code. Code complexity has an enormous projection on everything else, especially when talking on the business level. First and foremost the cost of development and time to market rises. And then comes the cost of maintenance.
Does this mean one doesn’t need to use reactor with spring and can rely on the non-reactive method and still get great performance?
Re: Virtual Threads Arrive in JDK 21, Ushering a New Era of Concurrency
#480Earlier quoted context omitted.
If you want to return a future you'll need to note that in the return type.
But that arguably doesn’t use this feature to its fullest — the most naive/easy to comprehend way to do concurrency is to start up multiple threads calculating something and simply wait for all of them to return, and at this point you are free to use the calculated results as is. This is the most-idiomatic way to make java virtual threads (with a try-with-resources block)
Goroutines can wrap code you don't want to block callers, but in practice that get hidden behind APIs that return channels.