On Sat, 2014-11-22 at 06:30 -0500, Sam Perman wrote: > We're using 'EntityUtils.toString()' to consume the response on each > request. Is that not sufficient? >
This is sufficient as long as this method is used to consume content of _each_ response message, not just 200. If there is an execution path where this method is not called this almost definitively leads to resource leaks. Oleg > thanks > sam > > > On Saturday, November 22, 2014, Oleg Kalnichevski <[email protected]> wrote: > > > On Fri, 2014-11-21 at 21:00 +0000, Jaikit Savla wrote: > > > Closing Idle and Expired connection is application only when stream > > associated with Connection is closed, otherwise connections are not > > considered idle. Looks like there is leak in connections at your side. > > Below code snippet shows one example on how to close the stream in a > > guaranteed fashion. > > > HttpResponse response = httpClient.execute(httpGet); > > HttpEntity entity = response.getEntity(); String jsonString = null; > > try { InputStream instream = entity.getContent(); > > > /* do your processing with the stream */ } finally { > > EntityUtils.consumeQuietly(entity); } > > > Jaikit > > > > > > On Friday, November 21, 2014 12:48 PM, Sam Perman <[email protected] > > <javascript:;>> wrote: > > > > > > > > > > Jaikit is absolutely right. This section of the HttpClient tutorial may > > also be of help: > > > > > > http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e145 > > > > Oleg > > > > > Hello > > > > > > We have had a persistent issue in production where after a few days our > > > PoolingClientConnectionManager becomes unusable because there are no > > > available connections. It turns out all of the available connections are > > > “leased” (according to the PoolStats). > > > > > > I thought I was doing the right thing by writing an > > > IdleConnectionManagerThread as recommended in the docs. This thread will > > > call “closeExpiredConnections” and “closeIdleConnections” on a regular > > > interval. > > > > > > Looking at the implementation of AbstractConnPool.closeExpired and > > > AbstractConnPool.closeIdle I don’t understand how they work. In our case, > > > all of our connections are “leased”… but these methods only ever iterate > > > and close connections that are “available”. How do I clean up leased > > > connections? > > > > > > Iterator<E> it = this.*available*.iterator(); > > > while (it.hasNext()) { > > > E entry = it.next(); > > > if (entry.getUpdated() <= deadline) { > > > entry.close(); > > > RouteSpecificPool<T, C, E> pool = > > getPool(entry.getRoute()); > > > pool.remove(entry); > > > it.remove(); > > > notifyPending(pool); > > > } > > > } > > > > > > thanks > > > sam > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > <javascript:;> > > For additional commands, e-mail: [email protected] > > <javascript:;> > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
