-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate Scoped Values #108
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Do you already have a strategy to deal with Since public interface ScopedValueAccessor<V> {
/**
* @see ThreadLocalAccessor#key()
*/
Object key();
/**
* @see ThreadLocalAccessor#getValue()
*/
@Nullable
V getValue();
/**
* Returns a wrapped runnable that:
* <ol>
* <li>Adds value to the context of the current thread,</li>
* <li>Runs {@code runnable},</li>
* <li>Cleans up the context of the current thread.
* </ol>
*/
Runnable wrap(Runnable runnable, V value);
// Similar methods for `Callable<R>` and `Supplier<R>`.
...
} and use This approach, however seems very inefficient. The
This might require an inversion of the approach used by Concrete exampleThe current way to propagate Log4j's ThreadContext between threads is to create a However, there is another approach possible. Users can create a What do you think? |
Thanks for taking a look at this. Unfortunately, I haven't had the bandwidth to give this the attention it deserves yet. I have not looked into it beyond an initial read of the JEP. When I have time, I'd love to take a closer look at it and your proposal here. In the meantime, I'm seeing if anyone else from the team has bandwidth or thoughts on it. |
@ppkarwasz thanks for taking the time to consider this issue. I've seen From the perspective of the context-propagation library, we're aiming to provide a general solution that would be well aligned with other provider libraries that rely on
|
To be precise, For these 3 services you can use the same approach: they can write their data to a common storage, which can be a map of maps backed by a This common storage does not necessarily needs to be provided by From the perspective of Log4j, we must provide a On the other hand I would gladly maintain a |
I've started a discussion about it in the loom dev mailing list. Feel free to chime in @ppkarwasz |
Scoped Values (Preview) is proposed to target JDK 21: https://openjdk.org/jeps/446
I haven't put a ton of thought into what an integration with this might look like in context-propagation, but it seems worth investigating as a lightweight alternative to propagation via
ThreadLocal
. It would be good if we can give any feedback about Scoped Values before it exits preview.The text was updated successfully, but these errors were encountered: