users@jersey.java.net

[Jersey] Re: Runnable hangs using jersey-apache-client4 1.19

From: Martynas Jusevičius <martynas_at_graphity.org>
Date: Mon, 5 Dec 2016 18:33:12 +0100

Turned out to be not an HTTP problem after all. Sorry!

On Sun, Dec 4, 2016 at 3:50 PM, Martynas Jusevičius
<martynas_at_graphity.org> wrote:
> Hey all,
>
> I have been successfully using jersey-apache-client4 for a while, but
> after I refactored the application to use multiple threads, the client
> requests in Runnable seem to hang.
>
> I am using Jersey 1.19 and passing Client to threads spawned by a
> thread pool in ServletContextListener. The code in Runnable that reads
> the stream from ClientResponse
>
> InputStream is = fileResponse.getEntityInputStream();
>
> seems to hang - the debugger steps to the next line that attempts to
> read, and after that the Runnable never continues.
>
> I am using ThreadSafeClientConnManager which is supposed to be
> thread-safe. In the log I can see some lines as
>
> 15:36:00,225 DEBUG ConnPoolByRoute:523 - No free connections
> [HttpRoute[{}->http://localhost:8080]][null]
>
> So I tried to increase the connection limits for my main routes:
>
> ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
> HttpRoute localhost = new HttpRoute(new HttpHost("localhost", 8080));
> HttpRoute remote = new HttpRoute(new HttpHost("remote.com", 1982));
> cm.setDefaultMaxPerRoute(50);
> cm.setMaxForRoute(localhost, 50);
> cm.setMaxForRoute(remote, 50);
> cm.setMaxTotal(100);
>
> clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
> cm);
>
> This doesn't seem to have any effect though. Any clues?
>
> Thanks.
>
> Martynas