java - 同时多个http请求

时间:2012-12-11 15:23:54

标签: java

有没有更好的方法同时发送数千个http GET请求?我的代码一个接一个地发送请求。看了其他的答案,但无法弄清楚。谢谢。

            for (int j=0; j<4; j++)
        {

        DefaultHttpClient httpclient = new DefaultHttpClient();
        CookieStore cookieStore = httpclient.getCookieStore();
        HttpGet httpget = new HttpGet("");
        try {
            HttpResponse response = httpclient.execute(httpget);
            List<Cookie> cookies = cookieStore.getCookies();
        } catch (Exception e) {}

        httpclient.getConnectionManager().shutdown();
        }

1 个答案:

答案 0 :(得分:3)

你应该创建多个线程,每个线程都应该执行HTTP请求

以下链接可能会有所帮助

http://hc.apache.org/httpclient-3.x/threading.html