Skip to content

Commit

Permalink
Create Dispatcher.Default threads with the same context classloader a…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
qwwdfsad committed Sep 4, 2023
1 parent 748ace5 commit 82079cb
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@ internal class CoroutineScheduler(
internal inner class Worker private constructor() : Thread() {
init {
isDaemon = true
/*
* `Dispatchers.Default` is used as *the* dispatcher in the containerized environments,
* isolated by their own classloaders. Workers are populated lazily, thus we are inheriting
* `Dispatchers.Default` context class loader here instead of using parent' thread one
* in order not to accidentally capture temporary application classloader.
*/
contextClassLoader = this@CoroutineScheduler.javaClass.classLoader
}

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

0 comments on commit 82079cb

Please sign in to comment.