Skip to content

APIs for easily changing the thread priority of default schedulers via hook. #3724

@JakeWharton

Description

@JakeWharton

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:

  • RxThreadFactory constructor overload which takes a thread priority to use. Not needed.
  • Factory methods on Schedulers for creating instances of io(), computation(), and newThread() except using a supplied ThreadFactory
    • 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" to Shedulers.

Metadata

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