Package com.squareup.okhttp
Class ConnectionPool
- java.lang.Object
-
- com.squareup.okhttp.ConnectionPool
-
public final class ConnectionPool extends Object
Manages reuse of HTTP and SPDY connections for reduced network latency. HTTP requests that share the sameAddressmay share aConnection. This class implements the policy of which connections to keep open for future use.The
system-wide defaultuses system properties for tuning parameters:http.keepAlivetrue if HTTP and SPDY connections should be pooled at all. Default is true.http.maxConnectionsmaximum number of idle connections to each to keep in the pool. Default is 5.http.keepAliveDurationTime in milliseconds to keep the connection alive in the pool before closing it. Default is 5 minutes. This property isn't used byHttpURLConnection.
The default instance doesn't adjust its configuration as system properties are changed. This assumes that the applications that set these parameters do so before making HTTP connections, and that this class is initialized lazily.
-
-
Constructor Summary
Constructors Constructor Description ConnectionPool(int maxIdleConnections, long keepAliveDurationMs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidevictAll()Close and remove all connections in the pool.Connectionget(Address address)Returns a recycled connection toaddress, or null if no such connection exists.intgetConnectionCount()Returns total number of connections in the pool.static ConnectionPoolgetDefault()intgetHttpConnectionCount()Returns total number of http connections in the pool.intgetMultiplexedConnectionCount()Returns total number of multiplexed connections in the pool.intgetSpdyConnectionCount()Deprecated.
-
-
-
Method Detail
-
getDefault
public static ConnectionPool getDefault()
-
getConnectionCount
public int getConnectionCount()
Returns total number of connections in the pool.
-
getSpdyConnectionCount
@Deprecated public int getSpdyConnectionCount()
Deprecated.
-
getMultiplexedConnectionCount
public int getMultiplexedConnectionCount()
Returns total number of multiplexed connections in the pool.
-
getHttpConnectionCount
public int getHttpConnectionCount()
Returns total number of http connections in the pool.
-
get
public Connection get(Address address)
Returns a recycled connection toaddress, or null if no such connection exists.
-
evictAll
public void evictAll()
Close and remove all connections in the pool.
-
-