Skip to content

Commit 82079cb

Browse files
committed
Create Dispatcher.Default threads with the same context classloader as the dispatcher itself
In order to properly operate in modularized on a classloader level environments with the absence of other workarounds (i.e. supplying application-specific thread factory) Fixes #3832
1 parent 748ace5 commit 82079cb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,13 @@ internal class CoroutineScheduler(
593593
internal inner class Worker private constructor() : Thread() {
594594
init {
595595
isDaemon = true
596+
/*
597+
* `Dispatchers.Default` is used as *the* dispatcher in the containerized environments,
598+
* isolated by their own classloaders. Workers are populated lazily, thus we are inheriting
599+
* `Dispatchers.Default` context class loader here instead of using parent' thread one
600+
* in order not to accidentally capture temporary application classloader.
601+
*/
602+
contextClassLoader = this@CoroutineScheduler.javaClass.classLoader
596603
}
597604

598605
// guarded by scheduler lock, index in workers array, 0 when not in array (terminated)

0 commit comments

Comments
 (0)