Module bus.http

Class RealConnectionPool

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

public final class RealConnectionPool extends Object
Manages reuse of HTTP and HTTP/2 connections for reduced network latency. An instance of this class maintains connections to multiple hosts. This class is thread-safe.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • RealConnectionPool

      public RealConnectionPool(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit)
      Creates 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 releases. Currently this pool holds up to 5 idle connections which will be evicted after 5 minutes of inactivity.
      Parameters:
      maxIdleConnections - The maximum number of idle connections to keep in the pool.
      keepAliveDuration - The time to keep idle connections alive.
      timeUnit - The time unit for the keep alive duration.
  • 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.
      Returns:
      The total number of connections.
    • evictAll

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

      public void connectFailed(Route failedRoute, IOException failure)
      Track a bad route in the route database. Other routes will be attempted first.
      Parameters:
      failedRoute - The route that failed.
      failure - The exception that caused the failure.