4 ms·
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
by jayd16 4y ago
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?
- throwaway2847 4y agoWhy would you need an async framework? All blocking I/O in the Java runtime has been changed to yield in a virtual thread.
- jayd16 4y agoThey added the structured concurrency package because you still need some kind of async framework for concurrency. Maybe the confusion is just the term "framework" as opposed to API? I don't mean a third party library is needed. The built in JDK alone is sufficient but you're still juggling promises/futures and the like.
- kaba0 4y agoYou don’t really need anything, they just make forking and subsequent joining+exception handling easier. You can just use the decades old thread api over virtual threads as is if you wish, but this “structured concurrency” concept, similar to goto vs structured control flow will make it much more productive and easier to reason about.
- jayd16 4y agoAlso true, but "use the decades old thread api" shouldn't count as a simplification, right?
- eklavya 4y agoIt should when you can just block left and right.
- jayd16 4y agoAgain, my point is that you often won't want to be blocking. You'll still want to run multiple async calls concurrently, and to do that the syntax is not the familiar synchronous style. You still need to use more complex apis.
- kosolam 4y agoThe complexity of an async lib/framework such as i.e. projectreactor stems from that your code stops being linear. And so is the dataflow. This is the core of the issue. You trade simplicity for performance. Using futures you can still write simple linear code. The problem is that thread based execution doesn’t scale well when the threads are mostly waiting for io, such as i.e. an http request. That is, it was a problem until virtual threads arrived.
- deleted 4y ago[deleted]
- grishka 4y agoJVM 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.
- jayd16 4y agoThe key point is concurrent calls. If you're calling out to multiple microservices or what have you (the case where you would actually hit 1M threads in the first place) you'll want to do that in a concurrent way with futures or fork/join and not in a synchronous style. One could argue that automatic promise wrapping and an await keyword ends up giving you cleaner, more simple code (despite the coloring).
- grishka 4y agoThe reason I dislike async/await is that the code doesn't clearly express what it actually does. I also dislike asynchronicity built directly into the language. It's just one more piece of context you have to keep track of, and the more context you need in your head to understand the code, the greater the potential for bugs, imo. It is good that Java forces one to explicitly write out their intentions. I really like the approach Java has chosen: keep the language itself as dumb as possible, but add all the niceties to the standard library and runtime.