Reputation: 11
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