I want to implement multiple parallel request in Retrofit 2. I have the following structure to make 3 request :
HistoricalRApi.IStockChart service=Historical
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;
}
}