public class CoroutineContextKt
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEBUG_PROPERTY_NAME
Name of the property that controls coroutine debugging. See newCoroutineContext.
|
static java.lang.String |
DEBUG_PROPERTY_VALUE_AUTO
Automatic debug configuration value for DEBUG_PROPERTY_NAME. See newCoroutineContext.
|
static java.lang.String |
DEBUG_PROPERTY_VALUE_OFF
Debug turned on value for DEBUG_PROPERTY_NAME. See newCoroutineContext.
|
static java.lang.String |
DEBUG_PROPERTY_VALUE_ON
Debug turned on value for DEBUG_PROPERTY_NAME. See newCoroutineContext.
|
static java.lang.String |
IO_PARALLELISM_PROPERTY_NAME
Name of the property that defines the maximal number of threads that are used by
CoroutineContextKt.getIO coroutines dispatcher. |
Modifier and Type | Method and Description |
---|---|
static CoroutineDispatcher |
getDefaultDispatcher()
The default
class CoroutineDispatcher that is used by all standard builders like
BuildersKt.launch , DeferredKt.async , etc if no dispatcher nor any other ContinuationInterceptor is specified in their context. |
static CoroutineDispatcher |
getIO()
The
class CoroutineDispatcher that is designed for offloading blocking IO tasks to a shared pool of threads. |
static NonExistentClass |
newCoroutineContext(NonExistentClass context,
Job parent)
Creates context for the new coroutine. It installs DefaultDispatcher when no other dispatcher nor
ContinuationInterceptor is specified, and adds optional support for debugging facilities (when turned on).
|
static NonExistentClass |
newCoroutineContext(NonExistentClass context)
Creates context for the new coroutine. It installs DefaultDispatcher when no other dispatcher nor
ContinuationInterceptor is specified, and adds optional support for debugging facilities (when turned on).
|
public static java.lang.String DEBUG_PROPERTY_NAME
Name of the property that controls coroutine debugging. See newCoroutineContext.
public static java.lang.String DEBUG_PROPERTY_VALUE_AUTO
Automatic debug configuration value for DEBUG_PROPERTY_NAME. See newCoroutineContext.
public static java.lang.String DEBUG_PROPERTY_VALUE_ON
Debug turned on value for DEBUG_PROPERTY_NAME. See newCoroutineContext.
public static java.lang.String DEBUG_PROPERTY_VALUE_OFF
Debug turned on value for DEBUG_PROPERTY_NAME. See newCoroutineContext.
public static java.lang.String IO_PARALLELISM_PROPERTY_NAME
Name of the property that defines the maximal number of threads that are used by CoroutineContextKt.getIO
coroutines dispatcher.
CoroutineContextKt.getIO
public static CoroutineDispatcher getDefaultDispatcher()
The default class CoroutineDispatcher
that is used by all standard builders like
BuildersKt.launch
, DeferredKt.async
, etc if no dispatcher nor any other ContinuationInterceptor is specified in their context.
It is currently equal to class CommonPool
, but the value is subject to change in the future.
You can set system property "kotlinx.coroutines.scheduler
" (either no value or to the value of "on
")
to use an experimental coroutine dispatcher that shares threads with CoroutineContextKt.getIO
dispatcher and thus can switch to
CoroutineContextKt.getIO
context without performing an actual thread context switch.
public static CoroutineDispatcher getIO()
The class CoroutineDispatcher
that is designed for offloading blocking IO tasks to a shared pool of threads.
Additional threads in this pool are created and are shutdown on demand.
The number of threads used by this dispatcher is limited by the value of
"kotlinx.coroutines.io.parallelism
" (IO_PARALLELISM_PROPERTY_NAME) system property.
It defaults to the limit of 64 threads or the number of cores (whichever is larger).
class CoroutineDispatcher
public static NonExistentClass newCoroutineContext(NonExistentClass context, Job parent)
Creates context for the new coroutine. It installs DefaultDispatcher when no other dispatcher nor ContinuationInterceptor is specified, and adds optional support for debugging facilities (when turned on).
Debugging facilities: In debug mode every coroutine is assigned a unique consecutive identifier. Every thread that executes a coroutine has its name modified to include the name and identifier of the currently running coroutine. When one coroutine is suspended and resumes another coroutine that is dispatched in the same thread, then the thread name displays the whole stack of coroutine descriptions that are being executed on this thread.
Enable debugging facilities with "kotlinx.coroutines.debug
" (DEBUG_PROPERTY_NAME) system property
, use the following values:
"auto
" (default mode, DEBUG_PROPERTY_VALUE_AUTO) -- enabled when assertions are enabled with "-ea
" JVM option.
"on
" (DEBUG_PROPERTY_VALUE_ON) or empty string -- enabled.
"off
" (DEBUG_PROPERTY_VALUE_OFF) -- disabled.
Coroutine name can be explicitly assigned using class CoroutineName
context element.
The string "coroutine" is used as a default name.
class CoroutineName
public static NonExistentClass newCoroutineContext(NonExistentClass context)
Creates context for the new coroutine. It installs DefaultDispatcher when no other dispatcher nor ContinuationInterceptor is specified, and adds optional support for debugging facilities (when turned on).
Debugging facilities: In debug mode every coroutine is assigned a unique consecutive identifier. Every thread that executes a coroutine has its name modified to include the name and identifier of the currently running coroutine. When one coroutine is suspended and resumes another coroutine that is dispatched in the same thread, then the thread name displays the whole stack of coroutine descriptions that are being executed on this thread.
Enable debugging facilities with "kotlinx.coroutines.debug
" (DEBUG_PROPERTY_NAME) system property
, use the following values:
"auto
" (default mode, DEBUG_PROPERTY_VALUE_AUTO) -- enabled when assertions are enabled with "-ea
" JVM option.
"on
" (DEBUG_PROPERTY_VALUE_ON) or empty string -- enabled.
"off
" (DEBUG_PROPERTY_VALUE_OFF) -- disabled.
Coroutine name can be explicitly assigned using class CoroutineName
context element.
The string "coroutine" is used as a default name.
class CoroutineName