}
}).start();
okhttp的同步运行方式如上,需要在子线程调用,我们先分析
@Override public Call newCall(Request request) {
return RealCall.newRealCall(this, request, false /* for web socket */);
}
此处创建了一个realCall,此处执行的是realcall的execute
@Override public Response execute() throws IOException {
同一个网络请求不可同时执行两次以上,否则会异常
synchronized (this) {
if (executed) throw new IllegalStateException(“Already E
xecuted”);
executed = true;
}
transmitter.timeoutEnter();
transmitter.callStart();
try {
1: client.dispatcher().executed(this);
2: return getResponseWithInterceptorChain();
} finally {
结束之后将请求移除出队列
client.dispatcher().finished(this);
}
}
接下来看1出的dispatcher的方法
/** Used by {@