Java 21 and Loom

I apologize if this has been addressed elsewhere; I could not find anything current…

Now that Java 21 has been released and Loom Virtual Threads are standard and supported, Structured Concurrency is still evolving, as well as Scoped Variables; I was wondering what the roadmap for Scala and Akka look like.

I sense that Loom brings blocking code to the same level of performance as non-blocking, reactive, functional code. The real beauty of Scala is that it supports both imperative and functional programming paradigms, giving developers more choices in how to ‘skin a cat.’

Are there functional representations of Virtual Threads and Structured Concurrency? From my Akka days, Actors offered Structured Concurrency, so I was really happy to see the Loom folks take this to heart. Scala has always been very innovative in terms of abstractions and hierarchies of abstraction, and I am curious what Scala will make of Virtual Threads and Structure Concurrency, maybe even Scoped Values.

Much of Loom has been the re-engineering of the JVM, a realm that Scala/Akka cannot touch.

Anyway, inquiring minds want to know what Scala/Akka will do with Java 21?

Have you seen this? Martin Odersky DIRECT STYLE SCALA Scalar Conference 2023

1 Like

Thanks, @spamegg1 I had not seen this before… some comments after watching it…

  1. Java Virtual Threads are built upon Delimeted Continutations in the JVM. While the DC API is not available yet, there is a strong desire at Oracle to make it available in the future for people who need/want lower-level access.
    • I am surprized Martin did not acknowledge that as it implies he does not know it.
    • I imagine Scala would want access to this API.
  2. It was not obvious initially that “Direct Style” is the same as blocking calls (vs. non-blocking). I wish he had explained the context better.
    • Or maybe I still don’t understand ‘Direct Style’
  3. Boundary/Break hurts my head, but I understand he is talking at a low level, such as delimited continuations, where there are applications other than Virtual Threads.
  4. Note: the JVM does a lot of magic to make stack frames on Virtual Threads very efficient, especially space-efficient, unlike Platform Threads.
    • This may be at the level of delimited continuations, but I would have to review the other presentations I have seen…
    • I hope that Scala is tracking the DC API in the JVM and possibly offering guidance to Project Loom on what they need/want from the DC API.
  5. Algebraic Effects is something I need to understand better…
    • I am not sure if Java 21 can help much here.
  6. Interesting take on Structured Concurrency…
    • But Structured Concurrency implies more than just cancellation; it implies composition and whether cancellation produces an error or a result.
  7. Okay, now I can see both the Loom imperative Structured Concurrency and the Scala functional Structured Concurrency.
    • Loom has less cognitive load
    • Scala has potentially more power and flexibility
    • Can’t say how they compare on performance
  8. Java 21 Virtual Threads and Structured Concurrency handles exceptions correctly and usefully with help from the JVM
    • Debugging and other tools work correctly and intuitively
    • It is not clear that Scala will
  9. I have already played with Java Structured Concurrency, calling it from Scala
    • Works without pain
    • I prefer Scala dynamic collections over Java Streams, where I keep forgetting that Java Streams are lazy.

That presentation was very interesting and useful. I look forward to what comes next out of Scala.

You might be interested in the SoftwareMill Ox project.

I’ve been following it here: Ox See the readme Resources section for details.

@objektwerks It looks like just information… but it looks like good information… thanks.

1 Like

GitHub - objektwerks/ox: Software Mill Ox feature tests using Scala 3. is information. GitHub - softwaremill/ox: Developer-friendly structured concurrency library for the JVM is a library.

1 Like

@nafg I can see a lot of work here, but I have some questions…

  1. Why not use Akka/Scala Streams instead of Go channels?
    • However, there is a lot of overhead with Akka/Scala Streams.
  2. has some interesting ideas about improving Java Streams.
  3. IMHO, I prefer collecting Java Structured Concurrency results with Scala collections than Java Streams because Java Streams are lazy, but maybe an improved Java Streams API will fix that.
  4. makes an interesting observation that Scoped Variables are similar to implicit variables in Scala… sort of… but this is a huge revelation, and I wish more people would use this analogy.
  5. I am not keen on the word supervised, but I don’t have a ready alternative because few people want to say concurrent-scope, which is technically more correct. I don’t know if there is a rationale for something like concurrent { scope { // do stuff; } }, just thinking out loud here… Naming things is hard… Or maybe scope { concurrent { // do stuff; } } ???

Anyway, I wish you success with your efforts, nice to see people playing with ideas.