java

orestis 2022-11-13T12:31:24.576329Z

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
seancorfield 2022-11-14T19:21:03.586679Z

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.

orestis 2022-11-14T19:44:13.692159Z

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

seancorfield 2022-11-14T20:39:55.319939Z

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.

seancorfield 2022-11-14T20:40:28.885579Z

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 🙂

orestis 2022-11-14T21:02:32.523739Z

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.

orestis 2022-11-14T21:03:34.014619Z

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

Prashant 2022-11-16T17:22:18.258259Z

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

Prashant 2022-11-16T17:23:02.591059Z

I was also toying with StructureTaskScope 😅 and came with this https://clojurians.slack.com/archives/C8NUSGWG6/p1666128152404049?thread_ts=1652433406.842079&cid=C8NUSGWG6