I was wondering if there will be any performance bottleneck or issues if I create one instance of OkHttpClient to serve my "entire android application". I.e.In my Application class, I create a static public variable that will contain a instance of OkHttpClient and whenever I need to do an http request I basically build a request object then use the created okhttpclient instance to fire the request.
Code to be like this
public class MyApplication extends Application {
public static OkHttpClient httpClient;
@Override
public void onCreate() {
super.onCreate();
httpClient = new OkHttpClient();
}
}
// Making request 1
Request request1 = new Request.Builder().url(ENDPOINT).build();
Response response = MyApplication.httpClient.newCall(request1).execute();
// Making request 2
Request request2 = new Request.Builder().url(ENDPOINT).build();
Response response = MyApplication.httpClient.newCall(request2).execute();