Nabil
11/11/2023, 11:12 AMconfig.preconfigured
(if it is set)? it looks like it is always creating a default OkHttp Dispatcher builder.dispatcher(Dispatcher())
Example: in the following code snippet the custom dispatcher is not used ⚠️
val threadFactory = ThreadFactory { runnable ->
val thread = Thread(runnable)
thread.name = "CustomThread-${thread.id}"
thread
}
val executorService = Executors.newFixedThreadPool(4, threadFactory)
val dispatcher = Dispatcher(executorService) // <---------- This Dispatcher is not used
val okHttpClient = OkHttpClient
.Builder()
.dispatcher(dispatcher)
.build()
// Create a Ktor HttpClient using the OkHttp engine
val ktorHttpClient = HttpClient(OkHttp) {
engine {
preconfigured = okHttpClient
}
}
Nabil
11/11/2023, 11:14 AMNils Kohrs
11/11/2023, 2:54 PMNils Kohrs
11/13/2023, 1:50 PMengine {
config {
dispatcher(
Dispatcher().apply {
maxRequestsPerHost = 200
maxRequests = 1000
}
)
}
}
Nils Kohrs
11/13/2023, 1:53 PMprivate fun createOkHttpClient(timeoutExtension: HttpTimeoutConfig?): OkHttpClient {
val builder = (config.preconfigured ?: okHttpClientPrototype).newBuilder()
builder.dispatcher(Dispatcher())
builder.apply(config.config)
config.proxy?.let { builder.proxy(it) }
timeoutExtension?.let {
builder.setupTimeoutAttributes(it)
}
return builder.build()
}
Nabil
11/13/2023, 2:19 PM