We are creating a ThreadSafeClient for doing the network IO in our
application using the following code:

DefaultHttpClient sClient;
final int MAX_TOTAL_CONNECTIONS = 50;
HttpParams sDefaultHttpParams = new BasicHttpParams();

ConnManagerParams.setMaxTotalConnections(sDefaultHttpParams,
MAX_TOTAL_CONNECTIONS);

sDefaultHttpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
                HttpVersion.HTTP_1_1);
sDefaultHttpParams.setParameter(
                CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8);
sDefaultHttpParams.setBooleanParameter(
                CoreConnectionPNames.STALE_CONNECTION_CHECK, true);
sDefaultHttpParams.setIntParameter(
                CoreConnectionPNames.CONNECTION_TIMEOUT, 40 * 1000);
sDefaultHttpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
                80 * 1000);
sDefaultHttpParams.setIntParameter(
                CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8192);

HttpClientParams.setRedirecting(sDefaultHttpParams, false);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory
                .getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory
                .getSocketFactory(), 443));

ClientConnectionManager manager = new ThreadSafeClientConnManager(
                sDefaultHttpParams, schemeRegistry);
sClient = new DefaultHttpClient(manager, sDefaultHttpParams);

Multiple threads call execute on sClient and it seems that sometimes,
some of the network connections stall. I read the document and found/
assumed that default value for MAX connections was set to 20. So, I
raised it to 50.

Questions:
1. What should be the ideal/recommended connection limit? I think 20
is enough.
2. Usually, developer download the byte stream and then parse
it(mostly XML content). Do they have to explicitly close the
InputStream to release the connection?

Please help.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to