Skip to content

Allow customization of default scheduler name on JVM #3465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kotlinx-coroutines-core/common/src/internal/SystemProps.common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ internal fun systemProp(
return parsed
}

/**
* Gets the system property indicated by the specified [property name][propertyName],
* or returns [defaultValue] if there is no property with that key.
*
* **Note: this function should be used in JVM tests only, other platforms use the default value.**
*/
internal fun systemProp(
propertyName: String,
defaultValue: String
): String = systemProp(propertyName) ?: defaultValue

/**
* Gets the system property indicated by the specified [property name][propertyName],
* or returns `null` if there is no property with that key.
Expand Down
9 changes: 7 additions & 2 deletions kotlinx-coroutines-core/jvm/src/scheduling/Tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import kotlinx.coroutines.internal.*
import java.util.concurrent.*


// Internal debuggability name + thread name prefixes
internal const val DEFAULT_SCHEDULER_NAME = "DefaultDispatcher"
/**
* The name of the default scheduler. The names of the worker threads of [Dispatchers.Default] have it as their prefix.
*/
@JvmField
internal val DEFAULT_SCHEDULER_NAME = systemProp(
"kotlinx.coroutines.scheduler.default.name", "DefaultDispatcher"
)

// 100us as default
@JvmField
Expand Down