Skip to content

Commit dc58806

Browse files
Allow customization of default scheduler name on JVM (#3465)
Fixes #3231
1 parent 4a5892f commit dc58806

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

kotlinx-coroutines-core/common/src/internal/SystemProps.common.kt

+11
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ internal fun systemProp(
5656
return parsed
5757
}
5858

59+
/**
60+
* Gets the system property indicated by the specified [property name][propertyName],
61+
* or returns [defaultValue] if there is no property with that key.
62+
*
63+
* **Note: this function should be used in JVM tests only, other platforms use the default value.**
64+
*/
65+
internal fun systemProp(
66+
propertyName: String,
67+
defaultValue: String
68+
): String = systemProp(propertyName) ?: defaultValue
69+
5970
/**
6071
* Gets the system property indicated by the specified [property name][propertyName],
6172
* or returns `null` if there is no property with that key.

kotlinx-coroutines-core/jvm/src/scheduling/Tasks.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ import kotlinx.coroutines.internal.*
99
import java.util.concurrent.*
1010

1111

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

1520
// 100us as default
1621
@JvmField

0 commit comments

Comments
 (0)