public final class IdleConnectionReaper extends Thread
Connections sitting around idle in the HTTP connection pool for too long will eventually be terminated by the AWS end of the connection, and will go into CLOSE_WAIT. If this happens, sockets will sit around in CLOSE_WAIT, still using resources on the client side to manage that socket. Many sockets stuck in CLOSE_WAIT can prevent the OS from creating new connections.
This class closes idle connections before they can move into the CLOSE_WAIT state.
This thread is important because by default, we disable Apache HttpClient's stale connection checking, so without this thread running in the background, cleaning up old/inactive HTTP connections, we'd see more IO exceptions when stale connections (i.e. closed on the AWS side) are left in the connection pool, and requests grab one of them to begin executing a request.
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Modifier and Type | Method and Description |
---|---|
static List<org.apache.http.conn.HttpClientConnectionManager> |
getRegisteredConnectionManagers() |
static boolean |
registerConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager)
|
static boolean |
registerConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager,
long maxIdleInMs)
Registers the given connection manager with this reaper;
|
static boolean |
removeConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager)
Removes the given connection manager from this reaper,
and shutting down the reaper if there is zero connection manager left.
|
void |
run() |
static boolean |
shutdown()
Shuts down the thread, allowing the class and instance to be collected.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
@Deprecated public static boolean registerConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager)
public static boolean registerConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager, long maxIdleInMs)
connectionManager
- Connection manager to registermaxIdleInMs
- Max idle connection timeout in milliseconds for this connection manager.public static boolean removeConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager)
public static List<org.apache.http.conn.HttpClientConnectionManager> getRegisteredConnectionManagers()
public static boolean shutdown()
Since this is a daemon thread, its running will not prevent JVM shutdown. It will, however, prevent this class from being unloaded or garbage collected, in the context of a long-running application, until it is interrupted. This method will stop the thread's execution and clear its state. Any use of a service client will cause the thread to be restarted.
Copyright © 2025. All rights reserved.