After reading all sort of docs on Java HttpURLConnection, I'm still quite confused as what kind of pooling it does and how it hands connections.
For example, the following code
URL url = new URL(someUrl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
OutputStream os = connection.getOutputStream();
InputStream is = connection.getInputStream();
/** Write something to os and flush */
/** Read from is */
os.close();
is.close();
connection.disconnect();
Do both
osandisneed to be flushed and closed for the underlying socket to be reusable?Will
connection.disconnect()close the underlying socket (and hence make it unreusable)? Doeskeep-aliveaffect this behavior?If I use different URL objects, but with the same URL, will the
connections created from them share the underlying sockets? How about when the host part of the URL is the same, but paths are different?When will pooled connections be destroyed?
What's the system property that controls the size of the pool?
Additionally, if you could also compare the Android version with Java it would be great.
Thanks