Skip to content

//okhttp/okhttp3/Dispatcher

Dispatcher

[jvm]\ class Dispatcher

Policy on when async requests are executed.

Each dispatcher uses an ExecutorService to run calls internally. If you supply your own executor, it should be able to run the configured maximum number of calls concurrently.

Constructors

Dispatcher [jvm]
fun Dispatcher(executorService: ExecutorService)
Dispatcher [jvm]
fun Dispatcher()

Functions

Name Summary
cancelAll [jvm]
@Synchronized
fun cancelAll()
Cancel all calls currently enqueued or executing. Includes calls executed both synchronously and asynchronously.
queuedCalls [jvm]
@Synchronized
fun queuedCalls(): List<Call>
Returns a snapshot of the calls currently awaiting execution.
queuedCallsCount [jvm]
@Synchronized
fun queuedCallsCount(): Int
runningCalls [jvm]
@Synchronized
fun runningCalls(): List<Call>
Returns a snapshot of the calls currently being executed.
runningCallsCount [jvm]
@Synchronized
fun runningCallsCount(): Int

Properties

Name Summary
executorService [jvm]
@get:Synchronized
@get:JvmName(name = "executorService")
val executorService: ExecutorService
idleCallback [jvm]
@get:Synchronized
@set:Synchronized
var idleCallback: Runnable? = null
A callback to be invoked each time the dispatcher becomes idle (when the number of running calls returns to zero).
maxRequests [jvm]
@get:Synchronized
var maxRequests: Int = 64
The maximum number of requests to execute concurrently. Above this requests queue in memory, waiting for the running calls to complete.
maxRequestsPerHost [jvm]
@get:Synchronized
var maxRequestsPerHost: Int = 5
The maximum number of requests for each host to execute concurrently. This limits requests by the URL’s host name. Note that concurrent requests to a single IP address may still exceed this limit: multiple hostnames may share an IP address or be routed through the same HTTP proxy.