Hi Ralph,

On Wed, 20 Mar 2024 at 17:11, Ralph Goers <ralph.go...@dslextreme.com> wrote:
>
> 1. I am experimenting with adding Thread support to ScopedContext as we 
> speak. It should be straightforward.
>
> I am not sure we ever want to deal with ScopedValue. ScopedContext provides 
> the same functionality plus integration with logging.

>From what I read about ScopedValue I am also less and less convinced
we want to use it. It can be used this way:

ScopedValue.where(KEY1, "value1").where(KEY2, "value2").run(() ->
doSomething());

Normally the values are not propagated to other "threads" or anything
of this sort. Sure, `doSomething` can run as virtual thread on
multiple Java `Thread`s (and each of them can run on multiple CPU
cores), but as soon as `doSomething` calls `new Thread` or calls
`ExecutorService.submit`, the context is lost.

There is a **special** executor (`StructuredTaskScope`) that will
automatically copy the values bound to a `ScopedValue` before jumping
threads, but there are specialized executors that already do that.

Why don't we implement the same functionality with a **minimal** API extension?

CloseableThreadContext.put("key1", "value1").put("key2",
"value2").run(() -> doSomething());

Piotr

Reply via email to