1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
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  }