Volley源码分析(三)

告别信号毛刺!手把手教你用ADS和IBIS-AMI模型搞定PCIe Gen3眼图仿真 本文详细介绍了如何使用Keysight ADS和IBIS-AMI模型进行PCIe Gen3眼图仿真,解决高速信号传输中的信号质量问题。从仿真环境搭建、S参数预处理到眼图优化与故障排除,提供了一套完整的工程实践指南,帮助工程师提升PCIe Gen3接口的信号完整性。 阅读详情

1.Volley源码分析(一)
2.Volley源码分析(二)
3.Volley源码分析(三)
4.XVolley-基于Volley的封装的工具类

上一篇分析完了RequestQueue的大部分方法,add执行完后,Volley就会执行线程操作了,在第一篇博客中提到,star方法执行时会创建1个缓存线程(CacheDispatcher)和4个网络线程(NetworkDispatcher),并开始这5个线程。这里我们就先看缓存线程。

public class CacheDispatcher extends Thread {

    private static final boolean DEBUG = VolleyLog.DEBUG;

    /** The queue of requests coming in for triage. */
    private final BlockingQueue<Request<?>> mCacheQueue;

    /** The queue of requests going out to the network. */
    private final BlockingQueue<Request<?>> mNetworkQueue;

    /** The cache to read from. */
    private final Cache mCache;

    /** For posting responses. */
    private final ResponseDelivery mDelivery;

    /** Used for telling us to die. */
    private volatile boolean mQuit = false;

    /**
     * Creates a new cache triage dispatcher thread.  You must call {@link #start()}
     * in order to begin processing.
     *
     * @param cacheQueue Queue of incoming requests for triage
     * @param networkQueue Queue to post requests that require network to
     * @param cache Cache interface to use for resolution
     * @param delivery Delivery interface to use for posting responses
     */
    public CacheDispatcher(
            BlockingQueue<Request<?>> cacheQueue, BlockingQueue<Request<?>> networkQueue,
            Cache cache, ResponseDelivery delivery) {
        mCacheQueue = cacheQueue;
        mNetworkQueue = networkQueue;
        mCache = cache;
        mDelivery = delivery;
    }

    /**
     * Forces this dispatcher to quit immediately.  If any requests are still in
     * the queue, they are not guaranteed to be processed.
     */
    public void quit() {
        mQuit = true;
        interrupt();
    }

    @Override
    public void run() {
        if (DEBUG) VolleyLog.v("start new dispatcher");
        //设置缓存线程的优先级
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

        // Make a blocking call to initialize the cache.
        //初始化缓存内容,对应的硬盘缓存-DiskBasedCache
        mCache.initialize();

        while (true) {
            try {
                // Get a request from the cache triage queue, blocking until
                // at least one is available.
                //BlockingQueue的take方法,取出队列中队首的request,如果没有则阻塞,等待到有request到来
                final Request<?> request = mCacheQueue.take();
                request.addMarker("cache-queue-take");

                // If the request has been canceled, don't bother dispatching it.
                //如果request被取消,则结束当前这次,继续循环
                if (request.isCanceled()) {
                    request.finish("cache-discard-canceled");
                    continue;
                }

                // Attempt to retrieve this item from cache.
                Cache.Entry entry = mCache.get(request.getCacheKey());
                //如果缓存里没有,则加入请求队列
                if (entry == null) {
                    request.addMarker("cache-miss");
                    // Cache miss; send off to the network dispatcher.
                    mNetworkQueue.put(request);
                    continue;
                }

                // If it is completely expired, just send it to the network.
                //如果缓存过期了,则加入请求队列
                if (entry.isExpired()) {
                    request.addMarker("cache-hit-expired");
                    request.setCacheEntry(entry);
                    mNetworkQueue.put(request);
                    continue;
                }

                // We have a cache hit; parse its data for delivery back to the request.
                //缓存中存在并且没有过期
                request.addMarker("cache-hit");
                //将数据包装成response
                Response<?> response = request.parseNetworkResponse(
                        new NetworkResponse(entry.data, entry.responseHeaders));
                request.addMarker("cache-hit-parsed");

                if (!entry.refreshNeeded()) {
                    // Completely unexpired cache hit. Just deliver the response.
                    //如果缓存不需要刷新,则直接将缓存回传
                    mDelivery.postResponse(request, response);
                } else {
                    // Soft-expired cache hit. We can deliver the cached response,
                    // but we need to also send the request to the network for
                    // refreshing.
                    request.addMarker("cache-hit-refresh-needed");
                    request.setCacheEntry(entry);

                    // Mark the response as intermediate.
                    response.intermediate = true;

                    // Post the intermediate response back to the user and have
                    // the delivery then forward the request along to the network.
                    //缓存需要刷新的话,先将缓存传回给客户,然后在将请求交给队列
                    mDelivery.postResponse(request, response, new Runnable() {
                        @Override
                        public void run() {
                            try {
                                mNetworkQueue.put(request);
                            } catch (InterruptedException e) {
                                // Not much we can do about this.
                            }
                        }
                    });
                }

            } catch (InterruptedException e) {
                // We may have been interrupted because it was time to quit.
                if (mQuit) {
                    return;
                }
            }
        }
    }
}

首先从继承关系我们就可以看出,创建的是个线程。既然是个线程,无可厚非,肯定是看它的run方法,从源码我们也可以看出,这里面除了构造方法就两个方法,quit和run,quit就不用说了,这里重点看一下run方法。
可以看到第51行先设置了当前线程的优先级,保证线程的顺利进行。
第55行,初始化了缓存,这里要说明一下,Volley现在默认使用的是硬盘缓存,这一点从初始化requestqueue时就可以看出来。

 RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);

后面可以看到,是个死循环,保证缓存线程一直执行。
第62行,可以看到从mCacheQueue.take取出请求。这里说明一下:
mCacheQueue是一个BlockingQueue,它的take方法,取出队列中队首的request,如果没有则阻塞,等待到有request到来
下面就是几种情况的判断:
1)如果该请求被取消——————->结束当前这次循环
2)如果缓存中不存在这个请求————>结束当前这次循环,并将请求加入网络请求队列
3)如果缓存过期了———————>结束当前这次循环,并将请求加入网络请求队列

当以上几种情况都不存在时,第95行,便要将缓存中这个request对应的请求结果封装成response

后面这个判断很奇妙,我一开始半天没理解,后来才懂了
这里判断缓存是否需要刷新,如果缓存不需要刷新,则将response回调给UI线程,如果需要刷新,同样先将response回调给UI线程,然后再将这个请求放入网络队列,进行请求并刷新缓存

缓存线程到这里基本上就看完了,现在来看网络线程

NetworkDispatcher。
    public class NetworkDispatcher extends Thread {
    /** The queue of requests to service. */
    private final BlockingQueue<Request<?>> mQueue;
    /** The network interface for processing requests. */
    private final Network mNetwork;
    /** The cache to write to. */
    private final Cache mCache;
    /** For posting responses and errors. */
    private final ResponseDelivery mDelivery;
    /** Used for telling us to die. */
    private volatile boolean mQuit = false;

    /**
     * Creates a new network dispatcher thread.  You must call {@link #start()}
     * in order to begin processing.
     *
     * @param queue Queue of incoming requests for triage
     * @param network Network interface to use for performing requests
     * @param cache Cache interface to use for writing responses to cache
     * @param delivery Delivery interface to use for posting responses
     */
    public NetworkDispatcher(BlockingQueue<Request<?>> queue,
            Network network, Cache cache,
            ResponseDelivery delivery) {
        mQueue = queue;
        mNetwork = network;
        mCache = cache;
        mDelivery = delivery;
    }

    /**
     * Forces this dispatcher to quit immediately.  If any requests are still in
     * the queue, they are not guaranteed to be processed.
     */
    public void quit() {
        mQuit = true;
        interrupt();
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    private void addTrafficStatsTag(Request<?> request) {
        // Tag the request (if API >= 14)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            TrafficStats.setThreadStatsTag(request.getTrafficStatsTag());
        }
    }

    @Override
    public void run() {
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        while (true) {
            //记录开始时间
            long startTimeMs = SystemClock.elapsedRealtime();
            Request<?> request;
            try {
                // Take a request from the queue.
                //从队首拿一个请求
                request = mQueue.take();
            } catch (InterruptedException e) {
                // We may have been interrupted because it was time to quit.
                if (mQuit) {
                    return;
                }
                continue;
            }

            try {
                request.addMarker("network-queue-take");

                // If the request was cancelled already, do not perform the
                // network request.
                //如果被取消则结束当前这次循环
                if (request.isCanceled()) {
                    request.finish("network-discard-cancelled");
                    continue;
                }
                //添加流量统计标签
                addTrafficStatsTag(request);

                // Perform the network request.
                //此处执行网络请求
                NetworkResponse networkResponse = mNetwork.performRequest(request);
                request.addMarker("network-http-complete");

                // If the server returned 304 AND we delivered a response already,
                // we're done -- don't deliver a second identical response.
                //如果服务器返回的304或者request已经存在response
                if (networkResponse.notModified && request.hasHadResponseDelivered()) {
                    request.finish("not-modified");
                    continue;
                }

                // Parse the response here on the worker thread.
                Response<?> response = request.parseNetworkResponse(networkResponse);
                request.addMarker("network-parse-complete");

                // Write to cache if applicable.
                // TODO: Only update cache metadata instead of entire record for 304s.
                if (request.shouldCache() && response.cacheEntry != null) {
                    mCache.put(request.getCacheKey(), response.cacheEntry);
                    request.addMarker("network-cache-written");
                }

                // Post the response back.
                //设置request已经返回response
                request.markDelivered();
                mDelivery.postResponse(request, response);
            } catch (VolleyError volleyError) {
                volleyError.setNetworkTimeMs(SystemClock.elapsedRealtime() - startTimeMs);
                parseAndDeliverNetworkError(request, volleyError);
            } catch (Exception e) {
                VolleyLog.e(e, "Unhandled exception %s", e.toString());
                VolleyError volleyError = new VolleyError(e);
                volleyError.setNetworkTimeMs(SystemClock.elapsedRealtime() - startTimeMs);
                mDelivery.postError(request, volleyError);
            }
        }
    }

    private void parseAndDeliverNetworkError(Request<?> request, VolleyError error) {
        error = request.parseNetworkError(error);
        mDelivery.postError(request, error);
    }
}

同样,这里重点看run方法。
和缓存线程一样,这里先设置了线程的优先级,保证线程的进行,并且利用死循环,使线程一直进行,不会被回收。
第58行,首先从队首拿了一个请求。
第61行,这里就是java常用的中断线程的方式。
第73行,如果请求被取消的话,则结束当前这次循环。
这里重点说明,第82行,这里就是我们整个Volley真正执行网络请求的地方。

NetworkResponse networkResponse = mNetwork.performRequest(request);
可以看到,这里request被当做参数传入,最后返回了一个response。而方法是属于mNetwork,这个mNetwork是在volley初始化requestqueue时传入的。
     /**
         * 创建一个网络请求
         */
        Network network = new BasicNetwork(stack);

        /**
         * 这里每次都会创建一个请求队列,可以优化,只创建一个全局队列吗
         */
        RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);

还记得这里吗,第一篇博客的时候说过,后面会介绍这个Network,这里就很好理解了,这个mNetwork就是在这里传入,真正执行网络请求就是在这个类中,而这个类的构造函数需要我们传入一个HttpStack对象,这里就是我们最开始说版本判断策略模式那里。这里我们可以进入BasicNetwork类中,看一下performRequest方法,来验证我们的想法。

@Override
    public NetworkResponse performRequest(Request<?> request) throws VolleyError {
        long requestStart = SystemClock.elapsedRealtime();
        while (true) {
            HttpResponse httpResponse = null;
            byte[] responseContents = null;
            Map<String, String> responseHeaders = Collections.emptyMap();
            try {
                // Gather headers.
                Map<String, String> headers = new HashMap<String, String>();
                addCacheHeaders(headers, request.getCacheEntry());
                //执行网络请求
                httpResponse = mHttpStack.performRequest(request, headers);
                StatusLine statusLine = httpResponse.getStatusLine();
                int statusCode = statusLine.getStatusCode();

                responseHeaders = convertHeaders(httpResponse.getAllHeaders());
                // Handle cache validation.
                if (statusCode == HttpStatus.SC_NOT_MODIFIED) {

                    Entry entry = request.getCacheEntry();
                    if (entry == null) {
                        return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null,
                                responseHeaders, true,
                                SystemClock.elapsedRealtime() - requestStart);
                    }

                    // A HTTP 304 response does not have all header fields. We
                    // have to use the header fields from the cache entry plus
                    // the new ones from the response.
                    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
                    entry.responseHeaders.putAll(responseHeaders);
                    return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data,
                            entry.responseHeaders, true,
                            SystemClock.elapsedRealtime() - requestStart);
                }

                // Some responses such as 204s do not have content.  We must check.
                if (httpResponse.getEntity() != null) {
                  responseContents = entityToBytes(httpResponse.getEntity());
                } else {
                  // Add 0 byte response as a way of honestly representing a
                  // no-content request.
                  responseContents = new byte[0];
                }

                // if the request is slow, log it.
                long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
                logSlowRequests(requestLifetime, request, responseContents, statusLine);

                if (statusCode < 200 || statusCode > 299) {
                    throw new IOException();
                }
                return new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart);
            } catch (SocketTimeoutException e) {
                attemptRetryOnException("socket", request, new TimeoutError());
            } catch (ConnectTimeoutException e) {
                attemptRetryOnException("connection", request, new TimeoutError());
            } catch (MalformedURLException e) {
                throw new RuntimeException("Bad URL " + request.getUrl(), e);
            } catch (IOException e) {
                int statusCode;
                if (httpResponse != null) {
                    statusCode = httpResponse.getStatusLine().getStatusCode();
                } else {
                    throw new NoConnectionError(e);
                }
                VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
                NetworkResponse networkResponse;
                if (responseContents != null) {
                    networkResponse = new NetworkResponse(statusCode, responseContents,
                            responseHeaders, false, SystemClock.elapsedRealtime() - requestStart);
                    if (statusCode == HttpStatus.SC_UNAUTHORIZED ||
                            statusCode == HttpStatus.SC_FORBIDDEN) {
                        attemptRetryOnException("auth",
                                request, new AuthFailureError(networkResponse));
                    } else if (statusCode >= 400 && statusCode <= 499) {
                        // Don't retry other client errors.
                        throw new ClientError(networkResponse);
                    } else if (statusCode >= 500 && statusCode <= 599) {
                        if (request.shouldRetryServerErrors()) {
                            attemptRetryOnException("server",
                                    request, new ServerError(networkResponse));
                        } else {
                            throw new ServerError(networkResponse);
                        }
                    } else {
                        // 3xx? No reason to retry.
                        throw new ServerError(networkResponse);
                    }
                } else {
                    attemptRetryOnException("network", request, new NetworkError());
                }
            }
        }
    }

可以看到,使用的其实也是Android原生的网络请求方式,只不过加入很多判断。

现在接着看NetworkDispatcher的run方法。
第88行,这里如果服务器返回了304,或者这个request已经返回了response则同样结束这次循环。

Response<?> response = request.parseNetworkResponse(networkResponse);

第94行,这里也是一个重点的地方,看到方法你会不会眼熟哪?如果你是熟练使用volley的话,你会发现这个方法就是我们自定义request中需要重写的方法。将网络请求返回的reponse封装转换为我们需要的response对象。
第99行,将请求的结果加入缓存,很好理解。
第106行,这里设置该request已经放回了response,对应的就是前面第88行的判断。
第107行,这里是我们接口回调的地方。这里需要详细看下mDelivery对象。

public RequestQueue(Cache cache, Network network, int threadPoolSize) {
        this(cache, network, threadPoolSize,
                //Looper.getMainLooper()对应主线程,所以请求成功后的接口回调对应是在主线程中执行。
                new ExecutorDelivery(new Handler(Looper.getMainLooper())));
    }

可以看到,在requestqueue的构造函数中,默认初始化了ExecutorDelivery类,这里需要注意一个地方Looper.getMainLooper()对应主线程,所以请求成功后的接口回调对应是在主线程中执行。

public ExecutorDelivery(final Handler handler) {
        // Make an Executor that just wraps the handler.
        mResponsePoster = new Executor() {
            @Override
            public void execute(Runnable command) {
                handler.post(command);
            }
        };
    }

可以看到,这里handler对应的是UI线程,执行的Runable。

@Override
    public void postResponse(Request<?> request, Response<?> response, Runnable runnable) {
        request.markDelivered();
        request.addMarker("post-response");
        mResponsePoster.execute(new ResponseDeliveryRunnable(request, response, runnable));
    }
public void run() {
            // If this request has canceled, finish it and don't deliver.
            if (mRequest.isCanceled()) {
                mRequest.finish("canceled-at-delivery");
                return;
            }

            // Deliver a normal response or error, depending.
            if (mResponse.isSuccess()) {
                //请求成功,接口回调
                mRequest.deliverResponse(mResponse.result);
            } else {
                mRequest.deliverError(mResponse.error);
            }

            // If this is an intermediate response, add a marker, otherwise we're done
            // and the request can be finished.
            if (mResponse.intermediate) {
                mRequest.addMarker("intermediate-response");
            } else {
                mRequest.finish("done");
            }

            // If we have been provided a post-delivery runnable, run it.
            if (mRunnable != null) {
                //这里当请求成功后,对应情况:需要刷新缓存,先将缓存返回成response后,再异步请求,刷新缓存。
                mRunnable.run();
            }
       }

这里只需要注意两个地方,首先接口回调的地方,可以看到deliverResponse这个方法是不是也很熟悉,自定义Request的时候,需要重写这个方法,执行我们的回调。

mRequest.deliverResponse(mResponse.result);

这里附上StringRequest的deliverResponse方法。

@Override
    protected void deliverResponse(String response) {
        if (mListener != null) {
            mListener.onResponse(response);
        }
    }

这样一看就很清楚了。
最后需要注意的一点:

  if (mRunnable != null) {
                //这里当请求成功后,对应情况:需要刷新缓存,先将缓存返回成response后,再异步请求,刷新缓存。
                mRunnable.run();
            }

这里会的对应情况是什么那,还记不记得当我们缓存需要刷新时,会怎么做,Volley会先将缓存的response返回,然后执行一个网络请求,并刷新缓存。

//缓存需要刷新的话,先将缓存传回给客户,然后在将请求交给队列
                    mDelivery.postResponse(request, response, new Runnable() {
                        @Override
                        public void run() {
                            try {
                                mNetworkQueue.put(request);
                            } catch (InterruptedException e) {
                                // Not much we can do about this.
                            }
                        }
                    });
华为OD机试真题 新系统2026-04-08 Python&JS 实现【配置操作失败数量统计】 模拟一个系统的命令行配置,包含添加、修改、删除三项操作,详情如下: 添加操作命令:add_rulerule_id=1rule_index = 18 修改操作命令: mod_rule rule_id= 1rule_index = 100 删除操作命令:del_rulerule_id=1 阅读详情

相关推荐

基于STM32的红外测温系统设计

为了实现本次的毕业设计,我搜集了大量的文献与资料,通过这些资料了解到红外测温的优点,与实现所需的基本器件,并设计了几个方案,最终选择了STM32作为主控芯片,为此还查阅了关于STM32的资料,在此次设计中采用的是MLX90614医用红外测温模块,通过查阅其数据手册了解其测量精度高且自带温度补偿,所以选择了该传感器作为红外测温模块,本次设计到此已经基本完成,硬件部分和软件部分的设计已基本完成。

weixin_112233的博客 1422

Volley 源码解析(二)

图片加载 用过Volley图片加载的老司机们可能对这段代码非常的熟悉:imageLoader.get( url, ImageLoader.getImageListener(iv, R.mipmap.aio_image_default, R.mipmap.aio_image_fail))只要把图片地址、要显示的ImageView给到ImageLoader就可以自动帮你

Nipuream 971

K8S证书过期解决办法之替换证书

k8s证书过期解决方案之替换证书

q_hsolucky的博客 1万+

Volley的任务执行

本文转载于Volley源代码分析 – 2:任务的执行,CacheDispatcher、NetworkDispatcher、ResponseDelivery,感谢原博主! 现在我们来看看CacheDispatcher和NetworkDispatcher从上面的框架图可以看出,大部分任务的执行都是通过CacheDispatcher和NetworkDispatcher来分发的。 从RequestQue

wxz的博客 376

QTest 单元测试框架及单元测试思考

qt 单元测试框架 QTEST 及思考

一个老菜鸟的学习分享 1万+

C#实战:5分钟搞定Modbus RTU通讯(基于NModbus4库)

本文详细介绍了如何使用C#和NModbus4库快速实现Modbus RTU通讯,包括环境配置、核心功能实现、性能优化及常见问题排查。通过代码示例和实用技巧,帮助开发者高效完成工业自动化设备的数据采集与控制任务。

weixin_30689307的博客 468

Volley简单学习使用五—— 源码分析三

一、Volley工作流程图: 二、Network     在NetworkDispatcher中需要处理的网络请求,由下面进行处理: NetworkResponse networkResponse = mNetwork.performRequest(request);看一下mNetwork的定义:(定义在NetworkDispatcher中) /** T

woliuyunyicai的专栏 1167

Spring AI Alibaba 1.x 源码分析-架构设计

本文通过分析Spring AI Alibaba 框架的源码,分析出其原理和架构设计,无论是用于项目开发、技术评估还是团队培训都具有重要价值。

program哲学 490

[Android]Volley源码分析(三)

上篇看了关于Request的源码,这篇接着来看下RequestQueue的源码。 RequestQueue类图: RequestQueue是一个请求调度队列,里面包含多个NetworkDispatcher调度器与一个CacheDispatcher调度器 主要属性: mSequenceGenerator: 请求序号生成器 mWaitingRequests: Staging a...

95

【OpenClaw从入门到精通】第34篇:医疗AI的“Agent OS”时代:基于WiseClaw构建医院专属智能体平台(2026实测版)

2026年医疗AI迈入实战落地新阶段,全球首个医疗OpenClaw平台WiseClaw正式发布,香港中文大学(深圳)医院完成业内首个私有化部署。本文基于真实医疗场景需求与公开技术资料,系统拆解医疗智能体平台的建设逻辑:从医疗Agent OS的五大核心特性切入,详解门诊病历质控、用药审查、医院运行管理三大临床场景的智能体搭建流程,提供完整的私有化部署代码、安全配置方案与实操演示。文章兼顾新手入门与进阶需求,严格遵循医疗合规要求,强调“只读不写+人工复核”原则,所有方案均经过虚拟实测验证。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 788

【网络与爬虫 44】Canvas指纹伪造技术:突破浏览器图形渲染检测的终极指南

Canvas和WebGL指纹是现代反爬虫系统中最难绕过的检测技术之一,它们通过分析浏览器图形渲染的细微差异来识别用户设备。本文将深入解析Canvas和WebGL指纹的工作原理,探讨其在反爬虫检测中的应用,并提供多种有效的伪造和绕过策略,帮助开发者理解并应对这些高级检测技术。

熵数实验室 1206

[Android]Volley源码分析(三)网络请求

在Volley源码分析(二)初始化中对

hunkpei的专栏 687

SAP-MM-供应商对账平台(功能集合)

(1)集成OA审批,线上核销,结果写入SAP; (2)集成SRM,线上与供应商对账确认,写入SAP; (3)集成财务付款结果确认写入,OA回传结果,定时同步SRM供应商平台。 欢迎留言交流,功能完善,如需要页面设计,请订阅专栏

qq_32198063的博客 748

Android网络框架-Volley(三) CacheDispatcher和NetworkDispatcher源码分析

在Android网络框架-Volley(一) 工作原理分析 中的流程图中我们知道Volley工作是有三个线程的:主线程、缓存线程和网络线程。这些线程的工作是建立在RequestQueue上的,上一篇文章 Android网络框架-Volley(二) RequestQueue源码分析以及建立一个RequestQueue 中我们分析了RequestQueue的源码以及最佳使用方式,这篇文章我们来分析

阿拉灯神灯的专栏 2059

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Volley源码解析(三) 有缓存机制的情况走缓存请求的源码分析

Volley源码解析(三) 有缓存机制的情况走缓存请求的源码分析 Volley之所以高效好用,一个在于请求重试策略,一个就在于请求结果缓存。 通过上一篇文章http://www.cnblogs.com/zharma/p/8338456.html 可以看到网络请求的流程逻辑分支是如何执行的。 接下来这篇文章就从具有请求缓存的流程去分析源码是采取的何种缓存策略。 继续以最简单的例子为起点分析...

dgd29756的博客 138

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Volley源码分析 (三):如何分发结果

Volley源码分析 (三):如何分发结果

luoxianfeng89的专栏 452

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Volley源码分析(三)NetWorkDispatcher分析

NetWorkDispatcher分析 NetWorkDispatcher和CacheDispatcher一样,继承于Thread,在run方法中实现一个无限循环,代码如下 @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); ...

weixin_30642267的博客 133

Android Volley的优缺点及源码分析

为什么volley不适合post大量数据,以及为什么不适合上传下载大量文件? 因为,volley中为了提高请求处理的速度,采用了ByteArrayPool进行内存中的数据存储的,如果下载大量的数据,这个存储空间就会溢出,所以不适合大量的数据。但是由于它的这个存储空间是内存中分配的,当存储的时候会先从ByteArrayPool中取出一块已经分配的内存区域, 不必每次存数据都要进行内存分配,而是先查...

csdn_aiyang的博客 2316

Volley框架源码分析

Volley框架分析Github链接Volley框架分析Volley源码解析为了学习Volley的网络框架,我在AS中将Volley代码重新撸了一遍,感觉这种照抄代码也是一种挺好的学习方式.再分析Volley源码之前,我们先考虑一下,如果我们自己要设计一个网络请求框架,需要实现哪些事情,有哪些注意事项?我的总结如下: 需要抽象出request请求类(包括url, params, method等),抽

小一的专栏 3603

Volley源码分析

Volley源码分析,缓存策略

MarvinYang 的博客 284

Volley源码分析二

在前两天我发布的文章:Volley源码分析一 中我较为详细的分析了Volley,今天继续,这篇文章会讲一些上一篇没有提到的比较细节的点,以及对于Volley源码中一些可以优化的实现的一些思考ByteArrayPool的分析byte[] 的回收池,用于 byte[] 的回收再利用,减少了内存的分配和回收。主要通过一个元素长度从小到大排序的ArrayList作为 byte[] 的缓存,另有一个按使用时间

ShanQuanQiang的专栏 2980

【网络编程】Volley使用与源码分析

在2013年Google I/O大会上推出了一个新的网络通信框架Volley。Volley既可以访问网络取得数据,也可以加载图片,并且在性能方面也进行了大幅度的调整,它的设计目标就是非常适合去进行数据量不大,但通信频繁的网络操作,而对于大数据量的网络操作,比如说下载文件等,Volley的表现就会非常糟糕。

xoliu的博客 1151

Android最火的框架系列(四)Volley

其实,本来不想写Volley的,由于前面写了一篇如何使用Eclipse搭建Android服务端的博客,今天,我们尝试用Volley去访问一下。其实,Volley已经不算是很火的网络请求框架了,Volley算是一个比较适合新手的网络请求库。Volley现在在Github上仅有2.3k的star,现在用的多的是Retrofit+okhttp。但是,Volley在某些场景下,使用起来还是挺不错...

zhaojun的博客 2万+

Volley框架(五):Volley源码分析

Volley框架(五):Volley源码分析 在前面几篇博客中我们已经把Volley的一些常见用法基本上说得差不多了。说了Volley那么多的用法,但是对于他的原理还不是很了解,所以这篇博客主要来分析一下Volley的执行过程。

ITRenj的博客 606

Volley详解+源码分析

基于1.2.1版本 github地址: https://github.com/google/volley 简介 简单它说,它就是谷歌官方用于更加方便发起网络请求的一个开源框架,它据有以下特点: 自动调度网络请求 并发请求网络(默认支持4个线程同时请求网络) 支持网络数据缓存到本地(可自定义缓存策略) 支持优先级设置(需要重写Request的getPriority() 方法) 支持取消网络请求 支持自定义网络请求方式(可改为OkHttp) 默认支持返回结果类型为String/Json/JsonArray.

guangdeshishe的博客 892

Android源码分析之理解Volley

0 参考链接 volley官网 手撕 Volley Volley全方位解析,带你从源码的角度彻底理解 Android Volley完全解析(四),带你从源码的角度理解Volley Android 面试之常用开源库 HTTP权威指南笔记 Java并发编程:阻塞队列 1 前言   Volley 是 Google 推出的轻量级 Android 异步网络请求框架和图片加载框架。在 ...

chenliguan的博客 1256
上一篇: Volley源码分析(二)
下一篇: XVolley-基于Volley的封装的工具类
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值