SUM
SUM

Reputation: 1661

java - multiple http requests at same time

Is there a better way to send thousands of http GET requests at the same time? 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();
}

Upvotes: 5

Views: 14256

Answers (1)

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26717

you should create multiple threads and each of them should perform an HTTP Request

the below link may help

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

Upvotes: 3

Related Questions