Skip to content

Using ThreadLocal in InjectableContext/ManagedContext. #47423

Answered by mkouba
skku-daniilkim asked this question in Q&A
Discussion options

You must be logged in to vote

So we do try to avoid using ThreadLocals in Quarkus. The ThreadLocalCurrentContext is only used for tests. If you work on a custom non-shared context for a normal scope then try to use the io.quarkus.arc.CurrentContextFactory to create a new io.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 to ThreadLocal otherwise.

You can obtain the CurrentContextFactory with Arc.container().getCurrentContextFactory(). There is also the io.quarkus.arc.impl.CurrentManagedContext, an abstract class that handles most of the logic. Finally, you will probably need the io.qua…

Replies: 1 comment 16 replies

Comment options

You must be logged in to vote
16 replies
@mkouba
Comment options

mkouba May 14, 2025
Collaborator

@skku-daniilkim
Comment options

@Ladicek
Comment options

Ladicek May 19, 2025
Collaborator

@skku-daniilkim
Comment options

@Ladicek
Comment options

Ladicek May 20, 2025
Collaborator

Answer selected by skku-daniilkim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants