public class HttpClientSingleton
extends java.lang.Object
OkHttpClient
instance in a singleton pattern. OkHttp performs best when you create
a single OkHttpClient instance and reuse it for all of your HTTP calls. This is because each client holds its own
connection pool and thread pools. Reusing connections and threads reduces latency and saves memory. Conversely,
creating a client for each request wastes resources on idle pools.Modifier | Constructor and Description |
---|---|
protected |
HttpClientSingleton()
Instantiates a new HTTP client singleton.
|
Modifier and Type | Method and Description |
---|---|
okhttp3.OkHttpClient |
createHttpClient()
Creates an
OkHttpClient instance with a new WatsonCookieJar . |
static HttpClientSingleton |
getInstance()
Gets the single instance of HttpClientSingleton.
|
protected HttpClientSingleton()
public static HttpClientSingleton getInstance()
public okhttp3.OkHttpClient createHttpClient()
OkHttpClient
instance with a new WatsonCookieJar
.