美文网首页
okhttp同步请求:RealCall、拦截器、dispatch

okhttp同步请求:RealCall、拦截器、dispatch

作者: 崽子猪 | 来源:发表于2019-06-03 10:36 被阅读0次

1.创建一个 OkHttpClient ---> new OkHttpClient();

2.创建一个 Request对象 ---> new Request.Builder();

3.创建一个Response对象(表示一个被执行的请求) ---> client.newCall(request) ---> 执行同步请求 call.execute();

ok同步使用方法

execute() ---> realyCall

executed():将我们同步的网络请求添加到同步的请求队列当中

if(executed) : 如果executed =true; 说明这个call对象已经被执行了.如果再次调用就会抛出异常,每一个call请求只能被执行一次

同步方法在RealyCall中的实现

1.client.dispatcher().executed(this):获取调度器对象

---> executed():在一个双向队列中存放同步请求.双向队列在我们新创建同步请求的时候就会把它放到队列当中去执行

executed做了什么

2.Response result == getResponseWithInterceptorChain() :OkHttp当中一个拦截器链的作用

3.最后走 client.dispatcher().finished(this) :将请求从dispatcher这个调度器中移除

相关文章

网友评论

      本文标题:okhttp同步请求:RealCall、拦截器、dispatch

      本文链接:https://www.haomeiwen.com/subject/pqjfxctx.html