[External] : Re: A new build and a new structured concurrency API
Ignaz Birnstingl
ignazb at gmail.com
Fri Nov 19 08:19:37 UTC 2021
Hi,
> The problem is that tasks are not observable entities. You can’t get a
> “task dump”, and so the relationships among tasks are reflected in their
> threads, but currently this can only be done if the thread is tied to a
> single task.
But at any given time an ExecutorService's worker thread _is_ tied to a
single task, or am I missing something? The only exception that comes to
mind is a direct executor [1].
> As older applications would need to be changed somewhat, anyway, to
> enjoy structured concurrency (as even the ExecutorService API were to
> support structure, it would need to be changed to do so, and so the
> use-sites would need to be changed as well), they might as well use the
> new mechanism and spawn a virtual thread per task.
Ok I think this was a misunderstanding. I thought that instead of doing
try (var s = StructuredExecutor.open("foo", VirtualThread::new)) ...
you would do
try (var s = StructuredExecutor.open("foo", Executors.
newVirtualThreadPerTaskExecutor())) ...
but you could also do
// Limit parallelism to 5
try (var s = StructuredExecutor.open("foo", Executors.
newFixedThreadPool(5))) ...
-- Ignaz
[1]
https://guava.dev/releases/19.0/api/docs/com/google/common/util/concurrent/MoreExecutors.html#directExecutor()
More information about the loom-dev
mailing list