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 java.io.IOException;
26
27 import org.apache.commons.httpclient.HttpClient;
28 import org.apache.commons.httpclient.methods.GetMethod;
29
30 public final class HttpClientThreadT extends Thread {
31
32 static String url;
33 private String name;
34
35 @Override
36 public void run()
37
38 {
39 url = "http://localhost/";
40
41 int counter = 100;
42 int batch = 1;
43
44 try {
45 // 1
46 // HttpClient client = new HttpClient();
47
48 // 2
49 // HttpClient client = new
50 // HttpClient(TestHttpClient.multiThreadedHttpConnectionManager);
51
52 // 3
53 HttpClient client = HttpClientT.httpClient;
54
55 long start = System.currentTimeMillis();
56 for (int x = 0; x < batch; x++) {
57 for (int j = 0; j < counter; j++) {
58 doGet(x, j, client);
59 }
60 }
61 System.out.println("thread " + this.name + " took " + (System.currentTimeMillis() - start));
62
63 } catch (Exception e) {
64 System.err.println("exception in thread" + this.name + " : " + e);
65 System.exit(-1);
66 }
67 }
68
69 /**
70 * @param name
71 */
72 public HttpClientThreadT(String name) {
73 super(name);
74 this.name = name;
75 }
76
77 private void doGet(int batch, int counter, HttpClient client) throws IOException {
78
79 GetMethod postMethod = new GetMethod(url);
80 try {
81 client.executeMethod(postMethod);
82 } finally {
83 postMethod.releaseConnection();
84 // System.out.println("thread "+this.name+" batch " + batch +
85 // " iteration " + counter + " done");
86 }
87 }
88
89 }