Class ConnectionPool



  • public final class ConnectionPool
    extends Object
    Manages reuse of HTTP and SPDY connections for reduced network latency. HTTP requests that share the same Address may share a Connection. This class implements the policy of which connections to keep open for future use.
    • Constructor Detail

      • ConnectionPool

        public ConnectionPool()
        Create a new connection pool with tuning parameters appropriate for a single-user application. The tuning parameters in this pool are subject to change in future OkHttp releases. Currently this pool holds up to 5 idle connections which will be evicted after 5 minutes of inactivity.
      • ConnectionPool

        public ConnectionPool(int maxIdleConnections,
                              long keepAliveDuration,
                              TimeUnit timeUnit)
    • Method Detail

      • idleConnectionCount

        public int idleConnectionCount()
        Returns the number of idle connections in the pool.
      • connectionCount

        public int connectionCount()
        Returns total number of connections in the pool. Note that prior to OkHttp 2.7 this included only idle connections and SPDY connections. Since OkHttp 2.7 this includes all connections, both active and inactive. Use idleConnectionCount() to count connections not currently in use.
      • evictAll

        public void evictAll()
        Close and remove all idle connections in the pool.