Package 

Class ConnectionPool


  • 
    public final class ConnectionPool
    
                        

    Manages reuse of HTTP and HTTP/2 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 Summary

      Constructors 
      Constructor Description
      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.
      ConnectionPool(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit)
    • Method Summary

      Modifier and Type Method Description
      synchronized int idleConnectionCount() Returns the number of idle connections in the pool.
      synchronized int connectionCount() Returns total number of connections in the pool.
      void evictAll() Close and remove all idle connections in the pool.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConnectionPool

        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.
      • ConnectionPool

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

      • idleConnectionCount

         synchronized int idleConnectionCount()

        Returns the number of idle connections in the pool.

      • connectionCount

         synchronized int connectionCount()

        Returns total number of connections in the pool. Note that prior to OkHttp 2.7 this includedonly idle connections and HTTP/2 connections. Since OkHttp 2.7 this includes all connections,both active and inactive. Use idleConnectionCount to count connections not currentlyin use.

      • evictAll

         void evictAll()

        Close and remove all idle connections in the pool.