eclipse-ee4j / eclipse-ee4j/jersey

[Jersey-Client] Support for custom implementations of concurrency - Feature Request

Open
#3,745 1 comment 0 reactions 0 assignees View on GitHub
Type: New Feature
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

In the current implementation of Jersey if we have a ThreadLocal and use async the only way to pass the ThreadLocal variables from the concurrent thread to async thread is with **Invocation.Builder.property(String name, Object value)**, if we have a ClientRequestFilter, We can get this information in async Thread with ClientRequestContext.getProperty(String name), per example:

## Call in original Thread
`Future future = webTarget.path("/api/account/123")
.request(MediaType.APPLICATION_JSON_VALUE)
.property("requestContextHolder", RequestContextHolder.getRequestAttributes())
.async()
.get(Account.class);`

## Filter that runs in async Thread
`public void filter(final ClientRequestContext requestContext) throws IOException {
RequestAttributes requestAttributes = (RequestAttributes) requestContext.getProperty("requestAttributes");
}`

This way solves the problem, but is not elegant for a case that we need to set this information for different APIs calls.
For this case would be nice if Jersey have a way to be more extensible, like [HystrixConcurrencyStrategy](https://netflix.github.io/Hystrix/javadoc/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.html), where we can define in one place what to copy from current thread to async thread or a place where we can fill ClientRequestContext with all the properties that we need in Async Thread for this request.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.