Understanding if URLConnection connections are really being pooled?
<p>I'm using URLConnection for my http client. Using Wireshark, I can see that setting up an https connection can take up to four seconds. Therefore I would like to pool connections if possible to avoid the https setup time. My flow looks like this:</p>

<pre><code>public String work(String url) {
    HttpURLConnection conn = (HttpURLConnection)(new URL(url)).openConnection();
    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String response = br.readResponseFromConnection();
    conn.disconnect();
    br.close();
    return response;
}

public void onBtnClickTest() {
    work("https://example.com/echo?param=abc");
}
</code></pre>

<p>With the above setup, I click my test button twice, but it looks like the https setup is done for each call, which makes me think the connection isn't really being reused (at least not in the way that I was hoping). Through Wireshark I see something like the following :</p>

<pre><code>// first click
Client Hello
Server Hello 
Certificate, Server Hello Done
Client Key Exchange, Change Cipher Spec, Encrypted...
Encrypted Handshake Message...
Application Data

// second click, 20 seconds after my first click.
Client Hello
Server Hello 
Certificate, Server Hello Done
Client Key Exchange, Change Cipher Spec, Encrypted...
Encrypted Handshake Message...
Application Data
</code></pre>

<p>However, if I click the test button twice within a span of &lt; 5 seconds, it looks like the handshake is skipped for the second run, and I immediately see the "Application Data" message. I think I remember reading somewhere that URLConnection only keeps connections pooled for 5 seconds.</p>

<p>So my questions:</p>

<ol>
<li>Can URLConnection actually pool my connections in the way that I want, in that subsequent connections can skip the https handshake (if hitting the same domain)?</li>
<li>If the above is possible, is there a way to increase the duration that connections stay pooled? My application is unlikely to make http calls within 5 seconds of eachother.</li>
<li>I know HttpClient offers a pool manager to reuse a connection, but looks more complicated than URLConnection. Can it get me around # 1 &amp; 2 if they won't do what I need?</li>
</ol>

<p>Thank you</p>
