public final class ConnectionPool extends Object
Address的HTTP请求可能共享一个Connection
该类实现了哪些连接保持开放以供将来使用的策略| Modifier and Type | Field and Description |
|---|---|
Deque<RealConnection> |
connections |
RouteDatabase |
routeDatabase |
| Constructor and Description |
|---|
ConnectionPool()
使用适合于单用户应用程序的调优参数创建新的连接池。
这个池中的调优参数可能在将来的Httpd版本中更改。
目前这个池最多可以容纳5个空闲连接,这些连接将在5分钟不活动后被清除
|
ConnectionPool(int maxIdleConnections,
long keepAliveDuration,
TimeUnit timeUnit) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
connectionBecameIdle(RealConnection connection)
通知这个池
connection已经空闲。如果连接已从池中删除,并且应该关闭,则返回true。 |
int |
connectionCount()
返回池中的连接总数。注意,在Httpd 2.7之前,这只包括空闲连接 和HTTP/2连接
因为Httpd 2.7包含了所有的连接,包括活动的和非活动的。
使用
idleConnectionCount()来计数当前未使用的连接 |
Socket |
deduplicate(Address address,
StreamAllocation streamAllocation)
如果可能,将
streamAllocation持有的连接替换为共享连接。
当并发地创建多个多路连接时,这将恢复 |
void |
evictAll()
关闭并删除池中的所有空闲连接.
|
RealConnection |
get(Address address,
StreamAllocation streamAllocation,
Route route)
返回一个循环连接到
address,如果不存在这样的连接,
则返回null。如果地址尚未被路由,则路由为空. |
int |
idleConnectionCount()
返回池中空闲连接的数量
|
void |
put(RealConnection connection) |
public final Deque<RealConnection> connections
public final RouteDatabase routeDatabase
public ConnectionPool()
public ConnectionPool(int maxIdleConnections,
long keepAliveDuration,
TimeUnit timeUnit)
public int idleConnectionCount()
public int connectionCount()
idleConnectionCount()来计数当前未使用的连接public RealConnection get(Address address, StreamAllocation streamAllocation, Route route)
address,如果不存在这样的连接,
则返回null。如果地址尚未被路由,则路由为空.address - 地址streamAllocation - 协调者route - 路由public Socket deduplicate(Address address, StreamAllocation streamAllocation)
streamAllocation持有的连接替换为共享连接。
当并发地创建多个多路连接时,这将恢复address - 地址streamAllocation - 协调者public void put(RealConnection connection)
public boolean connectionBecameIdle(RealConnection connection)
connection已经空闲。如果连接已从池中删除,并且应该关闭,则返回true。connection - 连接信息public void evictAll()
Copyright © 2020. All rights reserved.