Quote from developer site
To reduce latency, this class may reuse the same underlying Socket for multiple request/response pairs. As a result, HTTP connections may be held open longer than necessary.
To reduce latency, this class may reuse the same underlying Socket for multiple request/response pairs.
does not mean that sockets are always reused, it just states that they MAY be reused. If two threads use two
URLConnections at the same time, they cannot share a socket as a single socket cannot be used simultanously by multiple threads.
URLConnection implementation guarantees that a single
URLConnection is independent from any other connections in the same runtime environement, so parallel connections cannot reuse their sockets.
However, if one thread closes its
URLConnection before the other thread opens its
URLConnection, they MAY reuse the existing socket.