[
https://issues.apache.org/jira/browse/HTTPCLIENT-839?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12693826#action_12693826
]
Oleg Kalnichevski commented on HTTPCLIENT-839:
----------------------------------------------
> Or will the connection also automatically be closed when the stream is read
> to the end via means other than consumeContent()?
The connection will not be closed automatically, but it will be automatically
released back to the manager. It is up to the connection manager to decide
whether to the connection can be (should be) kept alive.
The Important thing is to read the content stream to the end (until -1 is
returned), either by calling #consumeContent() or any other means.
> HTTPClient that shows how to use ThreadSafeClientConnManager does not consume
> response content, too.
Well, it does
---
if (entity != null) {
byte[] bytes = EntityUtils.toByteArray(entity);
System.out.println(id + " - " + bytes.length + " bytes read");
}
---
> how would I set the max connections per host then?
See ConnManagerParams / ConnManagerPNames
Oleg
> ThreadSafeClientConnManager blocks forever on getConnection()
> -------------------------------------------------------------
>
> Key: HTTPCLIENT-839
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-839
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpConn
> Affects Versions: 4.0 Beta 2
> Environment: Android 1.1 R1
> Reporter: Matthias
>
> I have set up a HttpClient object with a ThreadSafeClientConnManager as
> follows:
> BasicHttpParams httpParams = new BasicHttpParams();
> ConnManagerParams.setMaxTotalConnections(httpParams, 10);
> HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
> HttpProtocolParams.setUserAgent(httpParams, HTTP_USER_AGENT);
> SchemeRegistry schemeRegistry = new SchemeRegistry();
> int port = prefs.isDebugMode() ? 3001 : 80;
> schemeRegistry.register(new Scheme("http",
> PlainSocketFactory.getSocketFactory(), port));
> ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(
> httpParams, schemeRegistry);
> this.httpClient = new DefaultHttpClient(cm, httpParams);
> In one of my Android activities, I upload photos asynchronously using this
> client (i.e. from different threads). When POST-ing the data,
> ThreadSafeClientConnManager.getConnection() always blocks eternally during
> the third upload, waiting for a connection to become free (why does it wait
> anyway when I told it to use up to 10 connections, not just 2?). ANY
> subsequent attempt to call execute() on that client will block on that
> unreleased lock forever, rendering the whole client object useless.
> Here is the code I use to dispatch the request:
> private void sendPostRequest(String url, HttpEntity payload)
> throws ConnectionFailedException, HttpResponseException {
> try {
> HttpPost request = new HttpPost(url);
> request.setEntity(payload);
> request.setHeader(HTTP_CONTENT_TYPE,
> payload.getContentType().getValue());
> oauthConsumer.sign(url, request);
> HttpResponse response = httpClient.execute(request,
> new BasicHttpContext());
> validatePostResponse(response);
> } catch (HttpResponseException e) {
> throw e;
> } catch (Exception e) {
> throw new ConnectionFailedException(e);
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]