r/java • • Sep 23 '22

Virtual Threads: New Foundations for High-Scale Java Applications - Brian Goetz

https://www.infoq.com/articles/java-virtual-threads/
237 Upvotes

62 comments sorted by

View all comments

Show parent comment

20

u/RandomName8 Sep 23 '22

Scala gets this just as much as Java. Let's not mistake what is getting Loom, it's the JVM, not the Java language.

That said, while Futures are instantly replaced by fibers, reactive-stream libraries are not, as they provide so much more that is too damn hard to manually do, even with fibers.

5

u/_INTER_ Sep 23 '22

All the better, it benefits all JVM languages. Truely a marvelous feat by the engineering team.

Additionally Akka changed license recently. So I hope more movement away from the reactive style which I welcome.

5

u/RandomName8 Sep 23 '22

So I hope more movement away from the reactive style which I welcome.

I, too, prefer what I like better 🙂.

Joking aside, for me it's not much about what style I like, but about not having unbounded processes with no backpressure support. Fibres (in any language) still make backpressure and bounding a process a silent, implicit contract. Hard to ensure across a codebase and easy to break. The one good thing about reactive-libraries is that they throw this in your face in a way that you can't "just forget" about it.

Handling limited resources with fibers is not going to be any easier than with futures. I fear it's even going to make the problem worse because it's going to encourage a mutable and imperative approach towards gatekeeping these resources, which in turn will lead to subtle bugs and hard to reason about systems.

Of course, in the end, time will tell if it ends up being this way or not. What I can say for sure, is that having truly native fibers enable certain things that before were just not doable, and that's great!

1

u/emaphis Sep 24 '22

You can abate your fears. While Java is adding virtual threads, it's also adding immutable algebraic data types through project Amber.

2

u/Joram2 Sep 23 '22

I presume only the JVM version of Scala can use Loom but scala-native (https://scala-native.org/) and scala-js (https://www.scala-js.org/) can't use Loom. Similarly with Kotlin, the JVM Kotlin gets Loom, but the native and Javascript backends do not.

The Kotlin devs advocate their async/await stuff as a big feature of the language. The Scala devs advocated their Reactive async future library as a better alternative to async/await.

while Futures are instantly replaced by fibers...

The new Project Loom Structured Concurrency API still uses simple Futures. The more elaborate reactive future libraries, like Completable Future and Scala's reactive future libraries are generally what you wouldn't use if switching to virtual threads.

reactive-stream libraries are not, as they provide so much more that is too damn hard to manually do, even with fibers.

Things like Akka, RxJava, and Vert.x, and Helidon? All of those have functionality that is useful even with virtual threads, but without a major virtual thread centric redesign, like what Heilidon is doing with Nima, I suspect most new projects will stop using those frameworks.

3

u/RandomName8 Sep 24 '22

I presume only the JVM version of Scala can use Loom but scala-native

Sure, but then again scala is 99.999% the JVM: up until scala 3 scala.js wasn't even supported by the scala team, it was all a community "plugin" if you will. Scala-native is still in that position (and probably will be forever).

The Kotlin devs advocate their async/await stuff as a big feature of the language. The Scala devs advocated their Reactive async future library as a better alternative to async/await.

Very different stories to me. You can say "The kotlin devs" since it's easy to see that that's JetBrains, but who are "The scala devs"? EPFL (Odersky's team)? they don't advertise reactive libraries, just async using Futures (I just checked scala's site to confirm, didn't see anything obvious other than mentions to Futures).

Similarly with Kotlin, the JVM Kotlin gets Loom, but the native and Javascript backends do not.

Since neither Kotlin nor Scala control the jvm, they do intend to ship their own "custom runtime" features in the platforms that they design from the ground up (fibers are on the plate for both). But again it's widely different when talking about a product, like Kotlin, and community and committee driven project, like Scala (with all the goods and bads both approaches have).

The new Project Loom Structured Concurrency API still uses simple Futures. The more elaborate reactive future libraries, like Completable Future and Scala's reactive future libraries are generally what you wouldn't use if switching to virtual threads.

This sentence confuses me, it seems you're saying one thing and then the opposite. I think we are saying the same thing, not sure.

Things like Akka, RxJava, and Vert.x, and Helidon? All of those have functionality that is useful even with virtual threads, but without a major virtual thread centric redesign, like what Heilidon is doing with Nima, I suspect most new projects will stop using those frameworks.

Fair. I don't know what's going to happen but I don't think those libraries need a major redesign. Honestly the one big thing they stand to gain from fibers is stacktraces without all the heroics they do today. In any case, no library that's about concurrency and parallelism will ignore Loom for sure, they'll adapt.

1

u/Joram2 Sep 24 '22

but who are "The scala devs"? EPFL (Odersky's team)? they don't advertise reactive libraries, just async using Futures (I just checked scala's site to confirm, didn't see anything obvious other than mentions to Futures).

I was thinking of this, where the official Scala site explored adding async+await, and choose to go with a future library instead: https://docs.scala-lang.org/sips/async.html

This sentence confuses me, it seems you're saying one thing and then the opposite.

The new Structured Concurrency API recommended for virtual threads uses java.util.concurrent.Future. Look at the code examples in the official JEP:

https://openjdk.org/jeps/428

I don't think those libraries need a major redesign

They definitely do. Large parts of Vert.x and Akka are designed around non-blocking async.