-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Description
On Android, the main thread is a sacred holy land at which we must all worship. As such this means other threads (ideally) shouldn't be favorably scheduled in priority with it. For network and filesystem operations this usually means using low priority threads.
One solution is to just use low priority threads on our own schedulers, but this doesn't affect code using the standard io()
and computation()
schedulers. Unfortunately there's a whole bunch of ceremony around how various schedulers are initialized which includes a mixed bag of public vs. non-public types and APIs which makes replacing them in a scheduler hook difficult.
I think the most easy way to accomplish this is the following:
-
Not needed.RxThreadFactory
constructor overload which takes a thread priority to use. - Factory methods on
Schedulers
for creating instances ofio()
,computation()
, andnewThread()
except using a suppliedThreadFactory
-
Schedulers.createIoScheduler(ThreadFactory)
-
Schedulers.createComputationScheduler(ThreadFactory)
-
Schedulers.createNewThreadScheduler(ThreadFactory)
-
Nice to have:
-
Schedulers
using these factory methods to create the default implementations. This involves moving the thread factories from the individual types "up" toShedulers
.