ScopedValue inheritance with unstructured concurrency?

Omar Aloraini aloraini.omar at gmail.com
Thu Jan 22 08:52:55 UTC 2026


I'm using `Executors.newThreadPerTaskExecutor` where I need a set of
independent actors(threads) to interact with each other. Right now,
everytime I start a new task I have to bind all my scoped values(just one
at the moment), but in the general case, it would be useful to have an
implementation of ExecutorService that captures all(or some) ScopeValues at
task submission point(and maybe at ES construction point).

```
Task task  = ....
executorService.submit(() -> {
  ScopedValue.where(AsyncScheduledTask.VALUE, task.asRunning())
    .where(TaskControlImpl.VALUE, new TaskControlImpl(task))
    .call(() -> {
```

It would be nice to have `Exuectors.scopeCapturing(ExecutorService
delegate, ScopeValues<?>... values)` or even without the varargs. Just
capture everything(if performance is not an issue).

I can't speak for people writing web servers or frameworks. But I think it
would be useful there as well.

In addition it will make ScopedValue the universal context
propagation mechanism for both structured and unstructured cases. The
current solution used by Spring and some other libraries `
https://github.com/micrometer-metrics/context-propagation`
<https://github.com/micrometer-metrics/context-propagation>.

Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20260122/cf19f6c3/attachment.htm>


More information about the loom-dev mailing list