okhttp流程分析

异步流程:

1)enqueue()加入队列,先加入等待队列;

2)promoteAndExecute(),从等待队列删除,加入到运行队列;

3)executorService.execute(this),运行AyncCall(Runable对象)的run()方法,间接执行execute()方法;

4)execute()方法会调用getResponseWithInterceptorChain()方法,并真正开始执行请求相关操作;

5)返回Response后,调用finished()方法,把当前call移出正在请求队列,promoteAndExecute()执行下个请求。

链式调用关键方法:

1)chain.proceed(request):执行chain里面封装的interceptor.intercept(chain),并构建下一个要执行的interceptor;

2)interceptor.intercept(chain):需要传入带有下一个interceptor的chain,在最后调用chain.proceed(request)方法。

你可能感兴趣的:(android)