1.StreamAllocation#newStream
这个方法是在连接是返回stream对象的。我们看这个方法里的这段代码。
RealConnection resultConnection = findHealthyConnection(connectTimeout, readTimeout,
writeTimeout, connectionRetryEnabled, doExtensiveHealthChecks);
//省略其他代码
findHealthyConnection方法返回健康的链接。我们继续跟踪代码。最后到了findConnection方法。
2.StreamAllocation#findConnection
//省略其他代码
RealConnection pooledConnection = Internal.instance.get(connectionPool, address, this);
//省略其他代码
上面的Internal.instance是啥玩意呢?这个是在OkHttpCLient的静态代码块中初始化的。我们看下他对应的get方法。
@Override public RealConnection get(
ConnectionPool pool, Address address, StreamAllocation streamAllocation) {
return pool.get(address, streamAllocation);
}
这里调用ConnectionPool的get方法返回一个RealConnection对象。
3.ConnectionPool#get
RealConnec