简体   繁体   English

java - 同时多个http请求

[英]java - multiple http requests at same time

Is there a better way to send thousands of http GET requests at the same time?有没有更好的方法可以同时发送数千个 http GET 请求? My code sends requests one after other.我的代码一个接一个地发送请求。 Have looked at other answers but could not figure it out.看过其他答案,但无法弄清楚。 Thanks.谢谢。

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();
}

you should create multiple threads and each of them should perform an HTTP Request你应该创建多个线程,每个线程都应该执行一个 HTTP 请求

the below link may help下面的链接可能会有所帮助

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM