import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
public class ConnectionPoolExample {
public static void main(String[] args) {
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.setMaxTotalConnections(50);
connectionManager.setDefaultMaxPerHost(20);
HttpClient httpClient = new HttpClient(connectionManager);
GetMethod getMethod = new GetMethod("http://example.com");
try {
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode == 200) {
String response = getMethod.getResponseBodyAsString();
System.out.println(response);
} else {
}
} catch (Exception e) {
e.printStackTrace();
} finally {
getMethod.releaseConnection();
}
}
}