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 and Type | Method and Description |
|---|---|
okhttp3.OkHttpClient |
configureClient(HttpConfigOptions options)
Configures the current
OkHttpClient instance based on the passed-in options, replaces
the current instance with the newly-configured instance and returns the new instance. |
okhttp3.OkHttpClient |
configureClient(okhttp3.OkHttpClient client,
HttpConfigOptions options)
Configures the specified
OkHttpClient instance based on the passed-in options,
and returns a new instance with the requested options applied. |
okhttp3.OkHttpClient |
createHttpClient()
Creates a new
OkHttpClient instance with a new ServiceCookieJar
and a default configuration. |
static HttpClientSingleton |
getInstance()
Gets the single instance of HttpClientSingleton.
|
public static HttpClientSingleton getInstance()
public okhttp3.OkHttpClient createHttpClient()
OkHttpClient instance with a new ServiceCookieJar
and a default configuration.OkHttpClient instancepublic okhttp3.OkHttpClient configureClient(HttpConfigOptions options)
OkHttpClient instance based on the passed-in options, replaces
the current instance with the newly-configured instance and returns the new instance.options - the HttpConfigOptions object for modifying the client instancepublic okhttp3.OkHttpClient configureClient(okhttp3.OkHttpClient client,
HttpConfigOptions options)
OkHttpClient instance based on the passed-in options,
and returns a new instance with the requested options applied.client - the OkHttpClient instance to configureoptions - the HttpConfigOptions instance for modifying the clientOkHttpClient instance with the specified options appliedCopyright © 2022 IBM Cloud Developer Experience. All rights reserved.