Skip to content

Instantly share code, notes, and snippets.

@MortezaNedaei
Created April 17, 2022 14:23
Show Gist options
  • Save MortezaNedaei/88f45d9ab396ccfa6908f15f594bcc49 to your computer and use it in GitHub Desktop.
Save MortezaNedaei/88f45d9ab396ccfa6908f15f594bcc49 to your computer and use it in GitHub Desktop.
How to change already existed OkHttp Client instance for other purposes?

❓ How to change already existed OkHttp Client instance for other purposes?

✅ You can customize a shared OkHttpClient instance with newBuilder().

This builds a client that shares the same connection pool, thread pools, and configuration. Use the builder methods to configure the derived client for a specific purpose.

👀 Sample:

OkHttpClient eagerClient = client.newBuilder()
        .readTimeout(500, TimeUnit.MILLISECONDS)
        .build();
    Response response = eagerClient.newCall(request).execute();
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment