gpt4 book ai didi

android - 为什么 Volley 在我的应用程序上使用这么多线程?

转载 作者:行者123 更新时间:2023-11-29 00:15:55 24 4
gpt4 key购买 nike

A sample listing of several Volley threads during normal-heavy app operation

我一直在查看我正在使用 Volley 的应用程序的线程转储。我已经查看了一半的线程,到目前为止,我已经找到了 40 个 volley 线程,其中大部分是 NetworkDispatcher,但也有一些是 CacheDispatcher。我们在一项 Activity 中使用截击。在 OnCreate 中:

volleyQueue = Volley.newRequestQueue(this);

然后,

ImageRequest s3ImageRequest = new ImageRequest(
decryptedImageURL.toString(),
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
imageBitmap = bitmap;
loadingImage = false;
}
},
0, // max width
0, // max height
null, // decode configuration
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Rlog.e(TAG, "Riff Playback: could not load image through Volley: " + decryptedImageURL);
volleyError.printStackTrace();
abortPlayback();
}
}
);
s3ImageRequest.setTag(TAG);
volleyQueue.add(s3ImageRequest);

是什么导致后台线程如此惊人地激增?

最佳答案

Volley 背后的主要设计决策之一是同时执行许多图像加载(或实际上任何小的 http 请求)。 Volley 的工作原理是创建许多专用于加载图像的线程,以便您可以同时执行这些网络调用。

有趣的是,Volley 实际上被称为 Volley,因为它得名于一组同时落在表面上的箭。尝试将网络请求想象成箭头,这样可能会更清楚一些。

您可以查看更多关于 Volley 的信息在这段精彩的 Google I/O 视频中,Volley 的创造者 Ficus Kirkpatrick 讲述了他的发明。

关于android - 为什么 Volley 在我的应用程序上使用这么多线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26917117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com