Mounika
Mounika

Reputation: 11

Reusing connections for Improving performance

I am using HttpURLConnection to make GET requests. Below is the code:

class ConnectClass  {
        private HttpURLConnection connection;

        public makerequest(URL url)  throws Exception {
        try {
            connection = (HttpsURLConnection) url.openConnection();
            ..... 
            } finally {
             connection.disconnect();
            }
        }
}

Is it a good idea to create connection and close it everytime for each request? How can I improve latency? Is it possible to reuse the existing connection without creating a new one everytime.

Any ideas? Thanks in advance.

Upvotes: 0

Views: 42

Answers (0)

Related Questions