Non-blocking/NIO HTTP requests in Java with Jetty's HttpClient
Posted by Kelvin on 05 Mar 2012 | Tagged as: programming, crawling
Jetty 6/7 contain a HttpClient class that make it uber-easy to issue non-blocking HTTP requests in Java. Here is a code snippet to get you started. Initialize the HttpClient object. HttpClient client = new HttpClient(); client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); client.setMaxConnectionsPerAddress(200); // max 200 concurrent connections to every address client.setTimeout(30000); // 30 seconds timeout; if no server reply, the […]