Can we set thread priority when using or initializ...
# coroutines
d
Can we set thread priority when using or initializing a dispatcher? Or maybe Coroutines system is designed to handle this? I see (on Android) that all threads from
CommonPool
or custom from
newSingleThreadContext
inherit the normail priority level. Which makes them equal to the main thread. Is there another mechanism to make the UI thread not affected? I'd like to make sure to prioritize it.
g
You can always convert any Executor (that creates threads with required priority) to Coroutine dispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/java.util.concurrent.-executor/as-coroutine-dispatcher.html
d
That's the only option I see, with making a dispatcher from a Handler.
v
CommonPool
is by default delegated to `ForkJoinPool#commonPool`and you can redefine its thread factory via system property
java.util.concurrent.ForkJoinPool.common.threadFactory
. For regular thread pool feel free to create an issue on github. But currently concept of separate pools is being reworked, so not sure we can address this problem soon
d
Yep, I see #261 on github issues. Maybe I'd rather comment on it. The general idea is main thread should have priority on any created thread (which are worker threads). In the case of an Android app, idk if it would be relevant on other implementations/platforms.
g
On Android ForkJoinPool available only from API level 21