Repository navigation
[RESTEASY-3313] Capture the ThreadContexts in the ResteasyProviderFactory to avoid repeated service loading. - #5124
Merged
Conversation
jamezp
force-pushed
the
RESTEASY-3313-thread-context
branch
from
November 3, 2026 15:15
4b9413b to
31e7cfb
Compare
…actory Previously the ThreadContext services were located with the ServiceLoader each time a task was submitted to a contextual executor, and registered ThreadContext providers were stored in the shared ResteasyContext data, which leaked them across threads and clients. - Keep the ServiceLoader.Provider handles in ThreadContexts, so the services are located once and a new instance of each is created per capture. Add a copy constructor which reuses the handles. Deprecate ThreadContexts.clear() as it is now a no-op. - Add ResteasyProviderFactory.getThreadContexts(). The provider factory owns its thread contexts and registered ThreadContext providers are added to them, not to the ResteasyContext. A child provider factory, including a client's, copies its parent's thread contexts. - Have the internal executors hold the ThreadContexts resolved when the executor is created. Add ContextualExecutors overloads which accept the ResteasyProviderFactory or the ThreadContexts. Executors wrapped without thread contexts resolve them from ResteasyProviderFactory.getInstance() on each submit. - Create the deployment's executors with the deployment's thread contexts after the provider factory is initialized, which also avoids creating the global provider factory with the deployment's class loader. The AsynchronousDispatcher uses its provider factory's thread contexts. - Use the client's thread contexts for the client and SSE executors, and the invocation's thread contexts for asynchronous invocations and client proxies, so ThreadContext providers registered on a WebTarget are captured. - Shut down the thread pool MultipartEntityPartWriter.asyncWriteTo() creates when it is not managed. - Document the lifecycle of ThreadContext implementations. https://redhat.atlassian.net/browse/RESTEASY-3313 Signed-off-by: James R. Perkins <[email protected]>
…tory when a deployment is stopped https://redhat.atlassian.net/browse/RESTEASY-3816 Signed-off-by: James R. Perkins <[email protected]>
jamezp
force-pushed
the
RESTEASY-3313-thread-context
branch
from
November 3, 2026 17:19
a3f964e to
9492155
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously the
ThreadContextservices were located with theServiceLoadereach time a task was submitted to a contextual executor,and registered
ThreadContextproviders were stored in the sharedResteasyContextdata, which leaked them across threads and clients.Providerhandles inThreadContexts, so theservices are located once and a new instance of each is created per
capture. Add a copy constructor which reuses the handles. Deprecate
ThreadContexts.clear()as it is now a no-op.ResteasyProviderFactory.getThreadContexts(). The provider factoryowns its thread contexts and registered
ThreadContextproviders areadded to them, not to the
ResteasyContext. A child provider factory,including a client's, copies its parent's thread contexts.
ThreadContextsresolved when theexecutor is created. Add
ContextualExecutorsoverloads which acceptthe
ResteasyProviderFactoryor theThreadContexts. Executors wrappedwithout thread contexts resolve them from
ResteasyProviderFactory.getInstance()on each submit.contexts after the provider factory is initialized, which also avoids
creating the global provider factory with the deployment's class
loader. The
AsynchronousDispatcheruses its provider factory's threadcontexts.
and the invocation's thread contexts for asynchronous invocations and
client proxies, so
ThreadContextproviders registered on aWebTargetare captured.
MultipartEntityPartWriter.asyncWriteTo()creates when it is not managed.
ThreadContextimplementations.