Does javax.ws.rs.client.Client cache the response data

243 Views Asked by At

I'm having javax.ws.rs.client.Client as a singleton using Guice dependency injection and have multiple threads in my threadpool share the singleton object.

@Provides
@Singleton
protected Client provideRestClient() {
    log.info("Http client instance created");
    ClientConfig cfg = new ClientConfig();
    cfg.property(ClientProperties.CONNECT_TIMEOUT, 5000);
    cfg.property(ClientProperties.READ_TIMEOUT, 5000);
    final Client client = ClientBuilder.newClient(cfg);
    return client;
}

When multiple threads use the singleton Client object to query the same endpoint within few seconds, the second threads gets empty response. Is this something to do with rest client caching the response data?

Code for using Client singleton object across threads

final Response response = client.target("URL").request().get();
if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    String response = response.readEntity(String.class);
}

Any help would be appreciated

0

There are 0 best solutions below