Class IdleConnectionMonitor

  • All Implemented Interfaces:
    Runnable

    public class IdleConnectionMonitor
    extends Thread
    • 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.

      • registerShutdownHook

        protected static void registerShutdownHook()
        Registers a shutdown hook with the Java Runtime to ensure that the IdleConnectionMonitor is properly shut down when the JVM exits.

        The shutdown hook will invoke the shutdown() method to stop the IdleConnectionMonitor thread and clear its connection managers.

      • cleanStaleReferences

        protected 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

        protected static int idleConnectionMonitorThreadSize()
      • getWaitTimeInSeconds

        public int getWaitTimeInSeconds()