Fork me on GitHub
#java
<
2022-11-13
>
orestis12:11:24

I see a lot of talk about Virtual Threads, but https://openjdk.org/jeps/428 which is also in JDK 19 seems a bigger deal for day-to-day uses: It introduces a StructuredTaskScope that can spawn sub tasks and can be nested, in such a way that the hierarchy can be monitored in JFR/Thread dumps, and most importantly, shutting down a parent scope cascades towards its children. This looks to be a great building block to get something like Erlang-style concurrency, as the relationship with children tasks is baked in the code. I tried it out from clojure and it looks very nice:

❤️ 2
seancorfield19:11:03

Search this Slack for structuredtaskscope and you'll see several folks have posted examples and expressed enthusiasm for that new feature. I haven't tried it myself -- just the virtual threads stuff -- but it does look interesting.

orestis19:11:13

thanks for the pointer, I've seen a couple of threads. It's a bit baffling to me why it hasn't received more attention in general, I've seen a ton of talks about Virtual Threads but nothing so far on the StructuredTaskScope

seancorfield20:11:55

I haven't gotten my head around it yet so I don't see why it's a "big deal" but clearly some people do so it is on my (long) list of "new stuff to learn" when I get some of that mythical "free time" people talk about.

seancorfield20:11:28

That said, we are creeping closer to JDK 19 in QA and then production and I'll have a good reason to learn this stuff at work as part of my job 🙂

orestis21:11:32

So far as I undesstand it, the big deal is that you can kill all children virtual threads / futures by just closing the top-level scope.

orestis21:11:34

With a few useful guardrails: if the scope gets garbage collected with still running children there will be an exception.

Prashant17:11:18

This one is a super concise talk about Loom and structured concurrency. https://www.youtube.com/watch?v=2nOj8MKHvmw