Module bus.http

Class ConnectionPool

java.lang.Object
org.miaixz.bus.http.accord.ConnectionPool

public final class ConnectionPool extends Object
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.
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

    • delegate

      public final RealConnectionPool delegate
      The real connection pool implementation.
  • Constructor Details

    • ConnectionPool

      public ConnectionPool()
      Create a new connection pool with tuning parameters appropriate for a single-user application. The tuning parameters in this pool may change in future Httpd 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 Details

    • idleConnectionCount

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

      public int connectionCount()
      Returns the total number of connections in the pool. Note that prior to Httpd 2.7 this included only idle connections and HTTP/2 connections. Since Httpd 2.7 this includes all connections, both active and inactive. Use idleConnectionCount() to count connections that are currently unused.
      Returns:
      The total number of connections.
    • evictAll

      public void evictAll()
      Closes and removes all idle connections in the pool.