📜  RxJava-计划程序

📅  最后修改于: 2020-11-12 05:31:41             🧑  作者: Mango


调度程序在多线程环境中用于与Observable运算符。

根据Reactive ,Scheduler用于计划运算符链如何应用于不同的线程。

默认情况下,一个Observable及其所应用的运算符链将在调用其Subscribe方法的同一线程上完成其工作,并通知其观察者。 SubscribeOn运算符通过指定应在其上运行Observable的另一个Scheduler来更改此行为。 ObserveOn运算符指定一个不同的Scheduler,Observable将使用该Scheduler向其观察者发送通知。

RxJava提供以下类型的调度程序-

Sr.No. Scheduler & Description
1

Schedulers.computation()

Creates and returns a Scheduler intended for computational work. Count of threads to be scheduled depends upon the CPUs present in the system. One thread is allowed per CPU. Best for event-loops or callback operations.

2

Schedulers.io()

Creates and returns a Scheduler intended for IO-bound work. Thread pool may extend as needed.

3

Schedulers.newThread()

Creates and returns a Scheduler that creates a new Thread for each unit of work.

4

Schedulers.trampoline()

Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes.

4

Schedulers.from(java.util.concurrent.Executor executor)

Converts an Executor into a new Scheduler instance.