private DefaultHttpClient createHttpClient() {
HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(28));
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpConnectionParams.setConnectionTimeout(params, 30000);
HttpConnectionParams.setSoTimeout(params, 30000);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
registry.register(new Scheme("https", PlainSocketFactory
.getSocketFactory(), 443));
ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(
params, registry);
return new DefaultHttpClient(manager, params);
}
如果一个应用只用到一个全局的HttpClient, ,那么要注意设置下
1.ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(28));
2.httpClient.execute以后response.getEntity().consumeContent();
如果碰巧2个都没设置,那么这个httpclient就会一直堵塞在那里了
posted on 2011-10-13 18:59
汪杰 阅读(784)
评论(0) 编辑 收藏 引用 所属分类:
Java