When a large number of requests are executed, a large number of threads are created to maintain idle connections, and these threads are in the TIMED_WAITING state for five minutes.
The following source code exists in the latest version:
class RealBackend(threadFactory: ThreadFactory) : Backend {
private val executor = ThreadPoolExecutor(
0, // corePoolSize.
Int.MAX_VALUE, // maximumPoolSize.
60L, TimeUnit.SECONDS, // keepAliveTime.
SynchronousQueue(),
threadFactory
)
}
From okhttp/TaskRunner.kt at master · square/okhttp · GitHub
Connection pool source code: okhttp/ConnectionPool.kt at master · square/okhttp · GitHub
Similar feedback in the GitHub repository issue:
- About the "okhttp3" thread pool issue · Issue #5607 · square/okhttp · GitHub
- ConnectionPool ThreadPool why use Integer.MAX_VALUE maximumPoolSize param ? · Issue #5963 · square/okhttp · GitHub
Why not use a lower value to limit the peak number of threads? Too high thread count may cause problems.