Establish connection by using multiple thread
<p>I am writing a Java program to compute the http connection time for (lets say) 5 http connection (to different IP). </p>

<p>The first scenario is, without threading, the program connect and testing the http server one by one which mean when finish one server testing then proceed to another. In this scenario, the time taken is very long. Moreover, the timeout is not working properly, for example, I have set the </p>

<pre><code>setConnectTimeout(5 * 1000);
setReadTimeout(5 * 1000);
</code></pre>

<p>but the time return by </p>

<pre><code>long starTime = System.currentTimeMillis();

c.connect();

String line;
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while ((line = in.readLine()) != null){
    page.append(line);

elapseTime = System.currentTimeMillis() - starTime;
</code></pre>

<p>can be more than 5 second, some even go up to 30 second (but I set 5 second as timeout only).</p>

<p>So, I make the implementation to be multithreading. But the result is more rediculous. I can't even get one successful connection now.</p>

<p>Now my question is, can we establish multiple connection by using multiple thread? If answer is yes, what I have to notice to avoid the issue above?</p>

<p>Thank.</p>

<p>*<strong><em>Extra info</em>*</strong>
1) I am computing the proxy connection speed, so, ya, the connection is proxy connection.
2) The threads that I created is around 100. I think it should be fine right?</p>
