Why is the performance of SSL different in a loop value in java
<p>I want to calculate the time which the ssl(client) needs to  establish a connection with a server and make the Handshake. Here is my code and it works fine.</p>

<pre><code>private boolean SslTlsConnection() throws IOException, NoSuchAlgorithmException, KeyStoreException, CertificateException, UnrecoverableKeyException, KeyManagementException {

        KeyStore client = KeyStore.getInstance("JKS");
        client.load(new FileInputStream(currentPath + "clientcert.keystore"), Password.toCharArray());

        KeyStore trust = KeyStore.getInstance("JKS");
        trust.load(new FileInputStream(currentPath + "myTrustStore.keystore"), Password.toCharArray());

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(client, Password.toCharArray());

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
        tmf.init(trust);

        SSLContext sc = SSLContext.getInstance("SSL");
        TrustManager[] trustManagers = tmf.getTrustManagers();
        sc.init(kmf.getKeyManagers(), trustManagers, new java.security.SecureRandom());

        SSLSocketFactory ssf = sc.getSocketFactory();
        sslsocket = (SSLSocket) ssf.createSocket(Properties.host, Properties.portNumber);

        sslsocket.startHandshake();
        System.out.println("Handshaking Complete");
        System.out.println("Just connected to " + sslsocket.getInetAddress() + "\n");

        transport = new IOTransport(sslsocket);
        return false;
}


private void close(){
 sslsocket.close();
}
</code></pre>

<p>I am just curious about the performance. I run multiple connections in a loop and i am calculating  the time ssl needs to do the handshake. My question is why the first time which client connect with ssl take so long time in compare with others. Did i something wrong?</p>

<pre><code>for (int i = 1; i &lt; loopvalue; i++) {
   long elapseTime = System.currentTimeMillis();
   SslTlsConnection()
   long elapseTime = (System.currentTimeMillis() - elapseTime);
   close();
}
</code></pre>

<p>I've tried tests . Here are the results</p>

<pre class="lang-none prettyprint-override"><code>SSL_Execution_Time
First Execution Time 453ms
Second Execution Time 85ms
Third Execution Time 90ms
</code></pre>