This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
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:
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.
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
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.
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 🙂
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.
With a few useful guardrails: if the scope gets garbage collected with still running children there will be an exception.
This one is a super concise talk about Loom and structured concurrency. https://www.youtube.com/watch?v=2nOj8MKHvmw
I was also toying with StructureTaskScope 😅 and came with this https://clojurians.slack.com/archives/C8NUSGWG6/p1666128152404049?thread_ts=1652433406.842079&cid=C8NUSGWG6