Skip to content

Provide an API to close Dispatchers.Default and Dispatchers.IO #2558

Closed
@qwwdfsad

Description

In containerized environments (Gradle build scripts, application containers, IDEA plugins), it is important to be able to unload the bundle of classes when the job is done.

Unfortunately, any code that touches our dispatchers (e.g. transitively, or via GlobalScope) cannot be unloaded: few indefinitely parked scheduler threads retain a strong reference to its class loader and cannot be terminated in any public way. For that, we should provide a public API to shutdown our dispatchers, destroy all their threads and make the outer classloader free.

The open question is how to establish a method contract in a way that nicely interacts with the fact that IO and Default are closely tightened and also take into account that depending on the system property, Dispatchers.Default can be backed by ForkJoinPool.commonPool that cannot be shut down (it doesn't suffer from this problem tho, because it's a JDK class that is always loaded by a bootstrap classloader).

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions