我是新来的装修2图书馆的,我想知道:有多少电话可以满足排队等候?
它是否使用PriorityBlockingQueue,它是一个自增长队列?
发布于 2018-08-30 09:09:35
这个问题让我想深入了解Retrofit源代码。这是我的结果,这可能是不正确的,但我想分享。如果你找到更好的答案,请纠正我!
包含maxRequests信息的代码是okhttp3.Dispatcher类,它们使用Deque而不是PriorityBlockingQueue。
public final class Dispatcher {
private int maxRequests = 64;
private int maxRequestsPerHost = 5;
....正如医生们说的:
每个调度程序使用一个
ExecutorService在内部运行调用。如果您提供自己的执行器,它应该能够同时运行{@linkplain #getMaxRequests the configured maximum}数量的调用。
也就是说,并发调用的最大数量取决于您所做的工作:
ExcutorService (通过使用OkHttpClient.Builder),则可以通过setMaxRequests函数设置其maxRequests值。executorService和默认的64并发请求。编辑:
关于您的问题的更多信息,可以满足等待队列的最大调用数是多少?,您可以在Dispatcher类中看到以下函数代码:
synchronized void enqueue(AsyncCall call) {
if (runningAsyncCalls.size() < maxRequests && runningCallsForHost(call) < maxRequestsPerHost) {
runningAsyncCalls.add(call);
executorService().execute(call);
} else {
readyAsyncCalls.add(call);
}
}如果达到runningAsyncCalls队列大小(并发请求),将向readyAsyncCalls添加新的call,并且该queue没有限制大小,这意味着最大调用值将为maxRequests
https://stackoverflow.com/questions/52090129
复制相似问题