-
Notifications
You must be signed in to change notification settings - Fork 24
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
Generalize ThreadLocal to ThreadScope #442
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I'm not sure I understand the value of replacing ThreadLocal
as a general interface.
You can declare subclasses of ThreadLocal
by overriding the three interesting methods, and in practice forward to Netty's TL and any other implementation, without any performance penalty.
Or am I missing something? This appears to be declaring a new interface in place of ThreadLocal
, but it's already useful as an interface-like.
storage/src/main/java/io/smallrye/context/storage/impl/UnsfafeThreadLocalScope.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/smallrye/context/impl/wrappers/ContextualSupplier2.java
Outdated
Show resolved
Hide resolved
…ThreadLocalScope.java Co-authored-by: Stéphane Épardaud <[email protected]>
…lSupplier2.java Co-authored-by: Stéphane Épardaud <[email protected]>
This is also doable, but a bit awkward to be honest: if I understand correctly what you're suggesting is subclassing Personally I don't like this design, but I agree that at the moment it will be less invasive and as I said I don't have a clear idea of how impactful the change that I'm proposing could be. |
Also cc @manovotn |
This is how it currently works ATM. I'm pretty sure you only have to override the three methods, since there are only three methods. I don't think it wastes any space either because there are no fields in this class, the default methods all store stuff in the thread. |
This pull request is a proposal to solve this issue and also a generalization of the
ThreadLocal
s' usage made inside smallrye allowing to plug different implementations including something more virtual threads friendly.I understand that replacing
ThreadLocal
with the newThreadScope
interface that I introduced with this pull request is quite invasive and could have a (relevant?) impact on other projects downstream. Nevertheless I believe that exposingThreadLocal
as we did so far is a leaky abstraction obliging us to use a very specific implementation for a quite general purpose.In essence this solution has a twofold advantage:
ThreadScope
interface limits the use of a ThreadLocal-like data structure to the only 3 methods that we really need.FastThreadLocal
which doesn't extendThreadLocal
or some other future implementations also playing well with virtual threads./cc @FroMage @Sanne @geoand @franz1981