Using ThreadLocal in InjectableContext/ManagedContext. #47423
-
Hello, Is it allowed to use ThreadLocal variables in the InjectableContext/ManagedContext implementations for custom CDI scopes? Will there be any problems? There is a ThreadLocalCurrentContext.java, but it does not seem to be used anywhere. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 16 replies
-
So we do try to avoid using You can obtain the You should end up with something like the built-in SessionContext. |
Beta Was this translation helpful? Give feedback.
So we do try to avoid using
ThreadLocal
s in Quarkus. TheThreadLocalCurrentContext
is only used for tests. If you work on a custom non-shared context for a normal scope then try to use theio.quarkus.arc.CurrentContextFactory
to create a newio.quarkus.arc.CurrentContext
. The Vertx implementation (which is used in most cases) attempts to use the Vertx duplicated context to store the bean instances if possible and falls back toThreadLocal
otherwise.You can obtain the
CurrentContextFactory
withArc.container().getCurrentContextFactory()
. There is also theio.quarkus.arc.impl.CurrentManagedContext
, an abstract class that handles most of the logic. Finally, you will probably need theio.qua…