ThreadPoolExecutor + Retrofit(同步请求) 在主线程中返回数据
/*核心池,最大面积池,保持时间,时间单位,工作队列*/
val executor = ThreadPoolExecutor(5, 10, 8000, TimeUnit.MILLISECONDS, LinkedBlockingDeque())
val future: Future<*> = executor.submit<Any> {
/*同步请求*/
val tokenJson: Response<Result<MutableList<ApiWarn>>> = MyRetrofit(Url.http).retrofit
.create(Api::class.java).apiWarn().execute()
if (tokenJson.body()!!.code == 0) {
val result = tokenJson.body()!!
}
}
/*分数类别*/
return result;
网友评论