hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthias (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HTTPCLIENT-839) ThreadSafeClientConnManager blocks forever on getConnection()
Date Mon, 30 Mar 2009 16:26:50 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-839?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12693825#action_12693825
] 

Matthias commented on HTTPCLIENT-839:
-------------------------------------

oh I forgot to ask:

how would I set the max connections per host then?

Cheers,
Matthias

> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message