小编Wik*_*rek的帖子

OkHttp中的ThreadPoolExecutor使用和异步操作的Retrofit的区别

OkHttp 2.0.0-RC1使用Dispatcher中ThreadPoolExecutor定义的:#getExecutorService

executorService = new ThreadPoolExecutor(
  0, Integer.MAX_VALUE,
  60, TimeUnit.SECONDS,
  new LinkedBlockingQueue<Runnable>(),
  Util.threadFactory("OkHttp Dispatcher", false));`
Run Code Online (Sandbox Code Playgroud)

这基本上是实现的Executors#newFixedThreadPool.

另一方面,Executors.newCachedThreadPool平台#defaultHttpExecutor中定义的Retrofit使用归结为:

executorService = new ThreadPoolExecutor(
  0, Integer.MAX_VALUE,
  60, TimeUnit.SECONDS,
  new SynchronousQueue<Runnable>(),
  someThreadFactory);
Run Code Online (Sandbox Code Playgroud)

任何人都有任何想法为什么OkHttp使用Executors#newFixedThreadPool和改造Executors#newCachedThreadPool

java threadpoolexecutor retrofit okhttp

0
推荐指数
1
解决办法
2516
查看次数

标签 统计

java ×1

okhttp ×1

retrofit ×1

threadpoolexecutor ×1