最近项目中使用到volley,自己就去网上学习volley并且研究了很长时间源码,网上有很多疑问关于volley到底有没有使用线程池?
今天我可以告诉你volley虽然没有用ThreadPoolExecutor但volley 里面使用了一个数组来存放 NetworkDispatcher 这功能就相当于是线程池,
只不过自己写了管理,默认开启4个线程。
<span style="font-size:18px;">// Create network dispatchers (and corresponding threads) up to the pool size.
for (int i = 0; i < mDispatchers.length; i++) {
NetworkDispatcher networkDispatcher = new NetworkDispatcher(mNetworkQueue, mNetwork,
mCache, mDelivery);
mDispatchers[i] = networkDispatcher;
networkDispatcher.start();
}</span>