-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoolingHttpClient.java
More file actions
43 lines (33 loc) · 1.41 KB
/
PoolingHttpClient.java
File metadata and controls
43 lines (33 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
public class PoolingHttpClient {
public static void main(String[] argv) throws InterruptedException {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm)
.build();
IdleConnectionMonitorThread idleConnectionMonitorThread = new IdleConnectionMonitorThread(cm);
idleConnectionMonitorThread.start();
String[] urisToGet = {
"http://www.google.com/",
"http://www.yahoo.com/",
"http://www.orange.com/",
"http://www.eugenpopa.ro/test",
"http://www.gsp.ro/"
};
clientThread[] threads = new clientThread[urisToGet.length];
for (int i = 0; i < threads.length; i++) {
HttpGet httpget = new HttpGet(urisToGet[i]);
threads[i] = new clientThread(httpClient, httpget);
}
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}
for (int j = 0; j < threads.length; j++) {
threads[j].join();
}
idleConnectionMonitorThread.shutdown();
}
}