1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package com.gisgraphy.test.standalone;
24
25 import org.apache.commons.httpclient.HttpClient;
26 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
27
28 public final class HttpClientT {
29
30 static MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager;
31
32 static HttpClient httpClient;
33
34 static String url;
35
36 @SuppressWarnings("deprecation")
37 public static void main(String[] args) throws Exception
38
39 {
40 multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
41 multiThreadedHttpConnectionManager.setMaxConnectionsPerHost(30);
42 multiThreadedHttpConnectionManager.setMaxTotalConnections(30);
43
44 url = args[0];
45
46 int counter = args.length > 1 ? Integer.parseInt(args[1]) : 100;
47
48
49 httpClient = new HttpClient(multiThreadedHttpConnectionManager);
50
51 Thread[] arrayThread = new Thread[counter + 1];
52 for (int j = 0; j < counter; j++) {
53 arrayThread[counter] = new HttpClientThreadT(j + "");
54 arrayThread[counter].start();
55 }
56 _waitForEver();
57
58 }
59
60 private static void _waitForEver() throws InterruptedException
61 {
62 while (true)
63 {
64 Thread.sleep(10000);
65 HttpClientT.multiThreadedHttpConnectionManager.deleteClosedConnections();
66 HttpClientT.multiThreadedHttpConnectionManager.closeIdleConnections(5);
67 System.out.println("Still alive..");
68 }
69
70 }
71
72 }