Class IdleConnectionMonitor

  • All Implemented Interfaces:
    Runnable

    public class IdleConnectionMonitor
    extends Thread
    • Field Detail

      • DEFAULT_IDLE_CONNECTION_MONITOR_THREAD_WAIT_TIME_IN_SECONDS

        public static int DEFAULT_IDLE_CONNECTION_MONITOR_THREAD_WAIT_TIME_IN_SECONDS
    • Method Detail

      • registerConnectionManager

        public static boolean registerConnectionManager​(org.apache.http.conn.HttpClientConnectionManager connectionManager,
                                                        int waitTimeInSeconds,
                                                        int idleTimeoutInSeconds)
        Registers the connection manager with the IdleConnectionMonitor thread;
        Parameters:
        connectionManager - Connection manager to register
        waitTimeInSeconds - The maximum time interval after which the check and closing of expired/idle connections is performed; this may happen more often
        idleTimeoutInSeconds - The idle timeout - close connections that have been idle longer than idleTimeoutInSeconds seconds
        Returns:
        true if the connection manager has been successfully registered; otherwise false.
      • removeConnectionManager

        public static boolean removeConnectionManager​(org.apache.http.conn.HttpClientConnectionManager connectionManager)
        Removes the connection manager from the IdleConnectionMonitor thread, and shuts down the thread if there is no connection manager left.
        Returns:
        true if the connection manager has been successfully removed; otherwise false.
      • run

        public void run()
        Specified by:
        run in interface Runnable
        Overrides:
        run in class Thread
      • closeIdleConnections

        public void closeIdleConnections()
        Close idle connections.

        As a side effect, updates the minimum wait time between checks.

      • cleanStaleReferences

        public static void cleanStaleReferences()
        Remove stale references that have been garbage-collected already.
      • shutdown

        public static boolean shutdown()
        Stops the execution of IdleConnectionMonitor thread by shutting down the thread and clears the connection managers in it.
        Returns:
        true if the shutdown process was initiated successfully, otherwise false.
      • idleConnectionMonitorThreadSize

        public static int idleConnectionMonitorThreadSize()
      • getWaitTimeInSeconds

        public int getWaitTimeInSeconds()
      • isIdleMonitorThreadShutdown

        public boolean isIdleMonitorThreadShutdown()