Skip to content

Instantly share code, notes, and snippets.

@neotyk
Forked from kevinherron/gist:575734
Created September 12, 2010 08:09
Show Gist options
  • Save neotyk/575928 to your computer and use it in GitHub Desktop.
Save neotyk/575928 to your computer and use it in GitHub Desktop.
import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.Request;
import com.ning.http.client.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
public class Problem {
public static void main(String[] args) throws Exception {
AsyncHttpClient client = new AsyncHttpClient();
Request request = client
.prepareGet(String.format("http://example.com/"))
.build();
List<Future<String>> fs = new ArrayList<Future<String>>();
for (int i = 0; i < 7; i++) {
fs.add(client.executeRequest(request, new AsyncCompletionHandler<String>() {
@Override
public String onCompleted(Response response) throws Exception {
return response.getResponseBody();
}
}));
}
for (Future<String> f : fs) {
System.out.println(f.get());
}
client.close();
System.out.println("Exiting...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment