DefaultHttpClientの使用に問題があります。
同じサーバー(> 2)に対していくつかのリクエストを同時に実行すると、それらがハングします(応答は受信されません)。次のすべてのリクエストもハングします。
これがコードです。
public class ConnectionService {
// Should be called once with application context
public static void initWithContext(Context ctx) {
// Creating custom multithread connection manager to handle multiple simultaneous requests
HttpParams params = new BasicHttpParams();
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
ConnManagerParams.setMaxTotalConnections(params, 200);
ConnPerRoute cpr = new ConnPerRoute() {
@Override
public int getMaxForRoute(HttpRoute httpRoute) {
return 50;
}
};
ConnManagerParams.setMaxConnectionsPerRoute(params, cpr);
httpClient = new DefaultHttpClient(cm, params);
httpClient.setCookieStore(new PersistentCookieStore(ctx));
}
static private DefaultHttpClient httpClient = null;
private JsonExecutorInterface requestExecutorForRelativePathAndParams(String path, WebParams params) throws UnsupportedEncodingException {
HttpPost postRequest = new HttpPost(rootUrl.toString() + path);
if(params != null) {
postRequest.setEntity(params.getFormEntity());
}
JsonExecutorProxy executor = new JsonExecutorProxy();
executor.setRequest(postRequest);
executor.setErrorsHandlerDelegate(this);
return executor;
}
}