On 22/01/2026 08:52, Omar Aloraini wrote:
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>.

Inheritance of ScopedValues is not compatibility with unstructured use as there is no guarantee that the the lifetime of the ScopedValue binding will fully enclose the lifetime of the "child" thread.

Although expensive, I suspect inheritable thread-locals (with copy rather than sharing) is closer to what you are looking for.

-Alan

Reply via email to