close
//執行緒池
Dispatcher dispatcher = new Dispatcher(
new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
Util.threadFactory("OkHttp Dispatcher", false)));
//最大的請求數量 def 64
dispatcher.setMaxRequests(64);
//主機同一個時間,最大的請求數量 def 5
dispatcher.setMaxRequestsPerHost(5);
//連線池
ConnectionPool connectionPool = new ConnectionPool(5, 5, TimeUnit.MINUTES);
OkHttpClient client = builder
.dispatcher(dispatcher)
.connectionPool(connectionPool)
.connectTimeout(5, TimeUnit.SECONDS)
.writeTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.followRedirects(true)
.retryOnConnectionFailure(false)
.build();
文章標籤
全站熱搜