Feedback on Structured Concurrency (JEP 525, 6th Preview)
Jige Yu
yujige at gmail.com
Mon Oct 13 14:31:07 UTC 2025
Thank you for your response, Viktor. I appreciate you weighing in and
clarifying the context of the design process, particularly your mention of
having "exhausted the design space several times over" and the extensive
prototyping, including for "functional combinators (composition of N-ary
concurrent ANDs and ORs)."
I agree with you on the importance of real-world feedback and the need to
tease apart API design discussions from observed user problems with a
specific design. My feedback is rooted in the latter: user-observed
problems with the current Structured Task Scope (STS) API's usability,
specifically its complexity for the common "concurrent AND" use case.
Before diving into the specific points, I want to say that I do not intend
to engage in open-ended design debates. I will not argue when it comes to
value judgements. For example, if you tell me the team believe the OR use
cases are critical despite I viewing them as niche, that's the difference I
wanted to find and it's what I sent this email for.
On Mon, Oct 13, 2025 at 2:31 AM Viktor Klang <viktor.klang at oracle.com>
wrote:
> Let me just weigh in by saying that these kinds of conversations are not
> ideal if the goal is to make change happen—as mentioned previously,
> real-world feedback is what we've found (over decades) to be the most
> important kind of feedback to make change happen.
>
> For the current incarnation of Structured Concurrency, Alan and I have
> exhausted the design space several times over with tons of different
> prototypes, including functional combinators (composition of N-ary
> concurrent ANDs and ORs).
>
> Not only is the current Structured Concurrency APIs *not envisioned* to
> be the complete solution, also I believe it to be important to tease apart
> questions—are we having a discussion about API design and its trade-offs in
> general, or are we discussing user-observed problems with a specific API
> design in particular?
>
My primary argument is not that a better, more complete set of combinators
exists, nor is it that the current design *should* support more use cases.
In fact, it is the opposite.
My point is about *subtraction*—the potential to achieve a simpler, more
intuitive API for the 80% use case by *deferring or omitting support for
less common use cases*, such as the concurrent OR.
-
Current Rationale Heard: The current, potentially complex, API is the
best trade-off because it handles both ANDs and ORs after exploring all
options.
-
My Question: Has a strategy of *doing less* been thoroughly explored and
documented, and if so, *what were the specific trade-offs that compelled
the inclusion of OR support, thus requiring a more complex imperative API
for the AND use case?*
I believe the trade-off discussion I'm missing is the one that directly
addresses the strawman I proposed:
1.
Introduce a simple, focused API for the common "concurrent AND" pattern
(with reasonably overloaded arity):
e.g., concurrently(()→fetchArm(),()→fetchLeg(),(arm, leg)→…)
2.
Defer "concurrent OR" and other niche cases to a separate mechanism,
perhaps a *mapConcurrent() gatherer *(or sibling).
With your earlier encouragement, I experimented with an alternative
gatherer. And it seems to be able to support ORs reasonably. Maybe not the
most convenient for all OR cases, but as I said, I view them as niche so a
bit inconvenience is fine if it means the main SC API gets to stay simple.
If supporting the OR pattern via STS is deemed critical, it might be worth
it to document the justification for paying the complexity cost in the
primary API. What is the key use case or design constraint that makes it
imperative to support ORs *within* the core Structured Task Scope API,
instead of *separating*, deferring them?
> The reason for separating those two is that the former is rather
> open-ended and its outcomes are rather limited in terms of impact, but the
> latter can lead to improvements for a large number of Java developers out
> there.
>
> To clarify, I don't want to sound dismissive, I want to make sure that
> everyone's time and effort is invested wisely.
>
> Adding some additional details around Gatherers.mapConcurrent(…)—one of
> the main reasons that it currently does not participate in Structured
> Concurrency is because it is a continuous window of concurrent
> work-in-progress with no "singular join", i.e. it produces results and
> starts new work whenever possible. This is further "complicated" by
> requiring that the results are produced on the calling thread to fit in
> with the evaluation model of the reference implementation of
> java.util.stream.Stream.
>
> As Alan said previously, we'd like for mapConcurrent to better integrate
> with Structured Concurrency, and we're considering the options there.
>
> As a personal anecdote, I had many situations in the evolution of this API
> where a solution would "intuitively" look better but it made something
> crucial either impossible or too easy to get wrong without noticing.
>
> Cheers,
> √
>
>
> *Viktor Klang*
> Software Architect, Java Platform Group
> Oracle
>
> Confidential – Oracle Internal
> ------------------------------
> *From:* loom-dev <loom-dev-retn at openjdk.org> on behalf of Alan Bateman <
> alan.bateman at oracle.com>
> *Sent:* Monday, 13 October 2025 08:38
> *To:* Jige Yu <yujige at gmail.com>
> *Cc:* loom-dev at openjdk.org <loom-dev at openjdk.org>
> *Subject:* Re: Feedback on Structured Concurrency (JEP 525, 6th Preview)
>
> On 13/10/2025 05:22, Jige Yu wrote:
> > :
> >
> > And this is the direction I'd hope the Loom team can more seriously
> > entertain: put a strong constraint on the API's imperative power, run
> > a thought experiment to see if the functional variant could offer
> > sufficient flexibility under the constraint.
> >
> I can't tell from your mails if you have read the JEP or not. We've
> tried to make it clear in every JEP that the goal is not to create the
> definitive structured concurrency API. This is an on-ramp API intended
> to "promote a style of concurrent programming that can eliminate common
> risks from cancellation and shutdown". Its sweet spot is in fan-out
> scenarios. Its deliberately imperative and kept as simple as possible.
> There will be other APIs. For example, we would like to bring channels
> based and other fan-in scenarios into the fold. We would like to
> eventually expose a lower level APIs for building other structured APIs
> outside of the JDK.
>
> On mapConcurrent. We've been around and around the topic of bringing it
> into the "structured fold". From your back and forth with Viktor on
> core-libs-dev then I think you understand the issues. When JEP 485 was
> preparing to make the gatherers API permanent it had to be decided if
> mapConcurrent should be pulled out. The conclusion was that it was
> useful enough as is, and we will look at improving or replacing it in
> the future. So yes, we of course want this, it's just not in the first API.
>
> -Alan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20251013/60a8ad6f/attachment.htm>
More information about the loom-dev
mailing list