<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div class="moz-cite-prefix">On 22/01/2026 08:52, Omar Aloraini
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAJ0wWSgnPWBsspe7cvUwpyfksoAorxTzstqNN2eS+oYXj9NEyw@mail.gmail.com">
<div dir="ltr">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).
<div><br>
</div>
<div>```</div>
<div>Task task = ....</div>
<div>executorService.submit(() -> {<br>
ScopedValue.where(AsyncScheduledTask.VALUE,
task.asRunning())<br>
.where(TaskControlImpl.VALUE, new TaskControlImpl(task))<br>
.call(() -> {</div>
<div>```</div>
<div><br>
</div>
<div>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).</div>
<div><br>
</div>
<div>I can't speak for people writing web servers or frameworks.
But I think it would be useful there as well.</div>
<div><br>
</div>
<div>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 `<a href="https://github.com/micrometer-metrics/context-propagation" target="_blank" moz-do-not-send="true">https://github.com/micrometer-metrics/context-propagation`</a>.</div>
<br>
</div>
</blockquote>
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.<br>
<br>
Although expensive, I suspect inheritable thread-locals (with copy
rather than sharing) is closer to what you are looking for.<br>
<br>
-Alan<br>
</body>
</html>