Questions on Build 18-loom+5-274 (2021/11/15)
Alan Bateman
Alan.Bateman at oracle.com
Wed Nov 24 10:53:34 UTC 2021
On 23/11/2021 20:42, Eric Kolotyluk wrote:
> Mike, as I have discovered, StructuredExecutor.open() functions like
> newVirtualThreadPerTaskExecutor(), one thread per task.
>
> While initially, I experimented with
> newVirtualThreadPerTaskExecutor(), I now only use StructuredExecutor
> because it's a better solution.
>
We can summarize this as ExecutorService for unstructured,
StructuredExecutor for structured.
For unstructured, an ExecutorService is "shared" (doesn't have an
owner), its usually long lived and often saved in static final field.
Anyone can submit tasks or shut it down. No inheritance of scope locals.
For structured, StructuredExecutor is owned by the thread that creates
it. It will be use try-with-resources to ensure is it closed, it would
be a bug to stash one of these executors in a static field. Forking is
confined to the owner and threads contained in the executor. Scope
locals are inherited.
-Alan.
More information about the loom-dev
mailing list