In the code below I will request 5 urls for million times, is there any way to establish a persistent connection?
//HTTPClient 4.2.5
static HttpClient httpClient;
static {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 1000);
HttpConnectionParams.setSoTimeout(params, 1000);
httpClient = new DefaultHttpClient(params);
}
public static String sendRequest(UUICRequest requset) throws
ClientProtocolException, IOException
{
HttpGet httpGet = new HttpGet(requset.toUrl());//only 5 urls will be request
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String ret = EntityUtils.toString(entity, "UTF-8");
EntityUtils.consume(entity);
httpGet.releaseConnection();
return ret;
}
Aucun commentaire:
Enregistrer un commentaire