类 IdleConnectionReaper
- java.lang.Object
-
- java.lang.Thread
-
- com.baidubce.http.IdleConnectionReaper
-
- 所有已实现的接口:
Runnable
public final class IdleConnectionReaper extends Thread
Daemon thread to periodically check connection pools for idle connections.Connections sitting around idle in the HTTP connection pool for too long will eventually be terminated by the BCE 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 BCE side) are left in the connection pool, and requests grab one of them to begin executing a request.
-
-
嵌套类概要
-
从类继承的嵌套类/接口 java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
字段概要
-
从类继承的字段 java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static booleanregisterConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager)Registers the given connection manager with this reaper;static booleanremoveConnectionManager(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.voidrun()static booleanshutdown()Shuts down the thread, allowing the class and instance to be collected.-
从类继承的方法 java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
方法详细资料
-
registerConnectionManager
public static boolean registerConnectionManager(org.apache.http.conn.HttpClientConnectionManager connectionManager)
Registers the given connection manager with this reaper;- 参数:
connectionManager- the connection manager to be registered.- 返回:
- true if the connection manager has been successfully registered; false otherwise.
-
removeConnectionManager
public 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.- 参数:
connectionManager- the connection manager to be registered.- 返回:
- true if the connection manager has been successfully removed; false otherwise.
-
shutdown
public static boolean shutdown()
Shuts down the thread, allowing the class and instance to be collected.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.
- 返回:
- true if an actual shutdown has been made; false otherwise.
-
-