square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.83k stars 9.16k forks source link

Using SynchronousQueue with ThreadPoolExecutor may cause OOM in Android 7.0 #3690

Closed koudle closed 6 years ago

koudle commented 6 years ago

The network thread usual is a time-consuming thread ,so when you use SynchronousQueue with ThreadPoolExecutor and submit many threads in a short time,it will new many threads and may cause OOM in Android 7.0 . There are limits on the number of threads on Android 7.0.

yschimke commented 6 years ago

Shouldn't the number of threads be capped at

OkHttp instances * (dispatcher.maxRequests + 1)

Are you seeing more than this number created? Are you reusing a single OkHttp instance?

Can you grab a thread dump?

Why do you specifically think the Synchronous Queue is the problem? These queues will generally hold Runnable instances, not create more Threads than it needs.

koudle commented 6 years ago

@yschimke Thank you very much for the prompt reply. You are right,I understand wrong.