2

enter image description here

Okhttp uses OkHttpClent to send requests.

can I use the same OkHttpClent instance to requests in different Threads ?

jimwi
  • 33
  • 3

1 Answers1

2

Yes. OkHttpClient is thread safe, and the use case you describe is expected. Do not create a new client instance per thread.

But at the same time, consuming a single Response from multiple threads is probably unwise.

See docs here https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/#okhttpclients-should-be-shared

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69