// Submit 50 requests using maximum 5 concurrent connections
Queue<RequestHandle> queue = new LinkedList<RequestHandle>();
for (int i = 0; i < 50; i++) {
AsyncConnectionRequest connRequest = connMgr.requestConnection();
connRequest.waitFor();
NHttpClientConnection conn = connRequest.getConnection();
if (conn == null) {
System.err.println("Failed to obtain connection");
break;
}
HttpContext context = conn.getContext();
BasicHttpRequest httpget = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
RequestHandle handle = new RequestHandle(connMgr, conn);
context.setAttribute("request", httpget);
context.setAttribute("request-handle", handle);
queue.add(handle);
conn.requestOutput();
}
// Wait until all requests have been completed
while (!queue.isEmpty()) {
RequestHandle handle = queue.remove();