支持多线程并发的HTTPCLIENT 池代码如下:package com.kanesoft.method.httppost;import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;public class MultiThreadedHttpConnection {
    private static HttpClient httpClient;
    private static final String contextType = "text/xml;charset=UTF-8";
    private static ExecutorService es = Executors.newFixedThreadPool(10);
    private static MultiThreadedHttpConnection mthc = new MultiThreadedHttpConnection();
    private static String url = "http://localhost:8000/2.php";
    private static int maxTotal = 300;
    private static int maxPerRout = 200;
    private static int connecttimeOut = 10000;
    private static int readTimeOut = 5000;    static {
        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
        cm.setMaxTotal(maxTotal);
        cm.setDefaultMaxPerRoute(maxPerRout);        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, connecttimeOut);
        HttpConnectionParams.setSoTimeout(params, readTimeOut);        httpClient = new DefaultHttpClient(cm, params);    }    private MultiThreadedHttpConnection() {    }    public static MultiThreadedHttpConnection getInstance() {
        return mthc;
    }    public void httpAsyncSendByMap(final Map<String, String> map) {
        es.execute(new postThread(mthc, map));
    }    private int sendDataByPost(Map<String, String> map) {
        Integer statusCode = -1;
        HttpPost post = new HttpPost(url);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        for (Map.Entry<String, String> m : map.entrySet()) {
            nvps.add(new BasicNameValuePair(m.getKey(), m.getValue()));
        }
        StringEntity entity;
        try {
            entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
            post.setEntity(entity);
            post.setHeader("Content-Type", contextType);
            HttpResponse response = httpClient.execute(post);
            statusCode = response.getStatusLine().getStatusCode();
            System.out.println(statusCode);
            if (statusCode != 200) {
                System.out.println("error quest");
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            post.abort();
        }        return statusCode;
    }    class postThread implements Runnable {
        private MultiThreadedHttpConnection m = null;
        private Map<String, String> map = null;        public postThread(MultiThreadedHttpConnection m, Map<String, String> map) {
            this.m = m;
            this.map = map;
        }        @Override
        public void run() {
            m.sendDataByPost(map);
        }
    }    public static void main(String[] args) {
        for (int i = 0; i < 10000; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("vcode", 1 + "");
            map.put("sid", i + "");
            MultiThreadedHttpConnection.getInstance().httpAsyncSendByMap(map);
        }
    }
}代码来自: http://topic.csdn.net/u/20121025/11/013ac02a-d2a1-41c7-becc-832d5162cecd.html?106214835
但是并发数量是有限制的,如果并发的数量较大,会出现超时的错误。
现在的问题是在执行命令的时候,
 HttpResponse response = httpClient.execute(post);
会产生很多输出,如下,这些输出可以不产生吗 ???2012-10-26 16:27:10:765:2710 [DEBUG] [org.apache.http.impl.conn.tsccm.ConnPoolByRoute#getFreeEntry]  
Getting free connection [{}->http://192.168.1.75][null]
2012-10-26 16:27:10:765:2710 [DEBUG] [org.apache.http.impl.client.DefaultHttpClient#execute]  
Stale connection check
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestAddCookies#process]  
CookieSpec selected: best-match
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestAuthCache#process]  
Auth cache not set in the context
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestTargetAuthentication#process]  
Target auth state: UNCHALLENGED
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestProxyAuthentication#process]  
Proxy auth state: UNCHALLENGED
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.impl.client.DefaultHttpClient#tryExecute]  
Attempt 1 to execute request
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.impl.conn.DefaultClientConnection#sendRequestHeader]  
Sending request: GET /web/getwinoptions.php?opt=0.24,0.25,0.26,0.51,0.52,1.24,1.25,1.26,1.51,1.52,2.24,2.25,2.26,2.51,2.52,3.24,3.25,3.26,3.51,3.52,0.28,0.29,0.30,0.31,0.32,0.33,0.34,0.35,1.28,1.29,1.30,1.31,1.32,1.33,1.34,1.35,2.28,2.29,2.30,2.31,2.32,2.33,2.34,2.35,3.28,3.29,3.30,3.31,3.32,3.33,3.34,3.35,0.36,0.37,0.38,0.39,0.40,0.41,0.42,1.36,1.37,1.38,1.39,1.40,1.41,1.42,2.36,2.37,2.38,2.39,2.40,2.41,2.42,3.36,3.37,3.38,3.39,3.40,3.41,3.42,0.80,0.81,0.82,0.83,0.84,0.85,0.86,1.80,1.81,1.82,1.83,1.84,1.85,1.86,2.80,2.81,2.82,2.83,2.84,2.85,2.86,3.80,3.81,3.82,3.83,3.84,3.85,3.86,0.53,0.54,0.56,0.57,0.58,0.61,0.62,0.63,0.64,0.55,0.59,1.53,1.54,0.56,1.57,1.58,1.61,1.62,1.63,1.64,1.55,1.59,2.53,2.54,2.56,2.57,2.58,2.61,2.62,2.63,2.64,2.55,2.59,3.53,3.54,2.56,3.57,3.58,3.61,3.62,3.63,3.64,3.55,3.59,&ts=1941296789 HTTP/1.1
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestAddCookies#process]  
CookieSpec selected: best-match
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.wire#wire]  
>> "GET /web/getwinoptions.php?opt=0.24,0.25,0.26,0.51,0.52,1.24,1.25,1.26,1.51,1.52,2.24,2.25,2.26,2.51,2.52,3.24,3.25,3.26,3.51,3.52,0.28,0.29,0.30,0.31,0.32,0.33,0.34,0.35,1.28,1.29,1.30,1.31,1.32,1.33,1.34,1.35,2.28,2.29,2.30,2.31,2.32,2.33,2.34,2.35,3.28,3.29,3.30,3.31,3.32,3.33,3.34,3.35,0.36,0.37,0.38,0.39,0.40,0.41,0.42,1.36,1.37,1.38,1.39,1.40,1.41,1.42,2.36,2.37,2.38,2.39,2.40,2.41,2.42,3.36,3.37,3.38,3.39,3.40,3.41,3.42,0.80,0.81,0.82,0.83,0.84,0.85,0.86,1.80,1.81,1.82,1.83,1.84,1.85,1.86,2.80,2.81,2.82,2.83,2.84,2.85,2.86,3.80,3.81,3.82,3.83,3.84,3.85,3.86,0.53,0.54,0.56,0.57,0.58,0.61,0.62,0.63,0.64,0.55,0.59,1.53,1.54,0.56,1.57,1.58,1.61,1.62,1.63,1.64,1.55,1.59,2.53,2.54,2.56,2.57,2.58,2.61,2.62,2.63,2.64,2.55,2.59,3.53,3.54,2.56,3.57,3.58,3.61,3.62,3.63,3.64,3.55,3.59,&ts=1941296789 HTTP/1.1[\r][\n]"
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestAuthCache#process]  
Auth cache not set in the context
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestTargetAuthentication#process]  
Target auth state: UNCHALLENGED
2012-10-26 16:27:10:781:2710 [DEBUG] [org.apache.http.client.protocol.RequestProxyAuthentication#process]  
Proxy auth state: UNCHALLENGED