CommonPool

object CommonPool : CoroutineDispatcher (source)

Platform and version requirements: JVM

Represents common pool of shared threads as coroutine dispatcher for compute-intensive tasks.

If there isn’t a SecurityManager present it uses java.util.concurrent.ForkJoinPool when available, which implements efficient work-stealing algorithm for its queues, so every coroutine resumption is dispatched as a separate task even when it already executes inside the pool. When available, it wraps ForkJoinPool.commonPool and provides a similar shared pool where not.

If there is a SecurityManager present (as would be if running inside a Java Web Start context) then a plain thread pool is created. This is to work around the fact that ForkJoinPool creates threads that cannot perform privileged actions.

Functions

dispatch

fun dispatch(
    context: CoroutineContext,
    block: Runnable
): Unit

Dispatches execution of a runnable block onto another thread in the given context.

toString

fun toString(): String

Inherited Functions

interceptContinuation

open fun <T> interceptContinuation(
    continuation: Continuation<T>
): Continuation<T>

Returns continuation that wraps the original continuation, thus intercepting all resumptions.

isDispatchNeeded

open fun isDispatchNeeded(context: CoroutineContext): Boolean

Returns true if execution shall be dispatched onto another thread. The default behaviour for most dispatchers is to return true.

Extension Functions

cancel

fun CoroutineContext.cancel(
    cause: Throwable? = null
): Boolean

Cancels Job of this context with an optional cancellation cause. The result is true if the job was cancelled as a result of this invocation and false if there is no job in the context or if it was already cancelled or completed. See Job.cancel for details.

cancelChildren

fun CoroutineContext.cancelChildren(
    cause: Throwable? = null
): Unit

Cancels all children of the Job in this context with an optional cancellation cause. It does not do anything if there is no job in the context or it has no children. See Job.cancelChildren for details.