Execute http request in parallel with Retrofit 2

元气小坏坏 提交于 2019-12-01 03:12:39

Thanks to Colin Gillespie link i have implemented what Jake Wharton says and this is the result:

 public static IStockChart getMyApiService() {
        OkHttpClient client=new OkHttpClient();
        Dispatcher dispatcher=new Dispatcher();
        dispatcher.setMaxRequests(3);
        client.setDispatcher(dispatcher);
       // OkHttpClient client = new OkHttpClient();
       //  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
       //  interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
       //  client.interceptors().add(interceptor);
        if(myService ==null){
            Retrofit retrofit=new Retrofit.Builder()
                    .baseUrl("http://chartapi.finance.yahoo.com/")
                    .addConverterFactory(JsonpGsonConverterFactory.create())
                    .client(client)
                    .build();
            myService=retrofit.create(IStockChart.class);
            return myService;
        } else {
            return myService;
        }



    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!