Scheduler is an object that schedules units of work. You can find common implementations of this
class in Schedulers.
| Modifier and Type | Class and Description |
|---|---|
| public abstract static class | Scheduler.Worker
Sequential Scheduler for executing actions on a single thread or event loop. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract Scheduler. | Returns: a Worker representing a serial queue of actions to be executedRetrieves or creates a new |
| public long | Returns: the scheduler's notion of current absolute time in millisecondsGets the current time, in milliseconds, according to this Scheduler. |
| public < a Scheduler and a Subscription S extends Scheduler & Subscription> S | Returns: the Scheduler with the customized execution behaviorthe function that takes a two-level nested Observable sequence of a Completable and returns
the Completable that will be subscribed to and should trigger the execution of the scheduled Actions. combine)Allows the use of operators for controlling the timing around when actions scheduled on workers are actually done. |
| Scheduler | back to summary |
|---|---|
| public Scheduler() | |
| createWorker | back to summary |
|---|---|
| public abstract Scheduler. Retrieves or creates a new
When work is completed it should be unsubscribed using
Work on a | |
| now | back to summary |
|---|---|
| public long now() Gets the current time, in milliseconds, according to this Scheduler.
| |
| when | back to summary |
|---|---|
| public <S extends Scheduler & Subscription> S when(Func1<Observable<Observable<Completable>>, Completable> combine) Allows the use of operators for controlling the timing around when
actions scheduled on workers are actually done. This makes it possible to
layer additional behavior on this
When
Finally the actions scheduled on the parent
When the Limit the amount concurrency two at a time without creating a new fix size thread pool:
Scheduler limitScheduler = Schedulers.computation().when(workers -> {
// use merge max concurrent to limit the number of concurrent
// callbacks two at a time
return Completable.merge(Observable.merge(workers), 2);
});
This is a slightly different way to limit the concurrency but it has some
interesting benefits and drawbacks to the method above. It works by
limited the number of concurrent
Scheduler limitScheduler = Schedulers.computation().when(workers -> {
// use merge max concurrent to limit the number of concurrent
// Observables two at a time
return Completable.merge(Observable.merge(workers, 2));
});
Slowing down the rate to no more than than 1 a second. This suffers from
the same problem as the one above I could find an Observable
operator that limits the rate without dropping the values (aka leaky
bucket algorithm).
Scheduler slowScheduler = Schedulers.computation().when(workers -> {
// use concatenate to make each worker happen one at a time.
return Completable.concat(workers.map(actions -> {
// delay the starting of the next worker by 1 second.
return Completable.merge(actions.delaySubscription(1, TimeUnit.SECONDS));
}));
});
| |
Unsubscribing the Worker cancels all outstanding work and allows resources cleanup.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public long | Returns: the scheduler's notion of current absolute time in millisecondsGets the current time, in milliseconds, according to this Scheduler. |
| public abstract Subscription | |
| public abstract Subscription | Returns: a subscription to be able to prevent or cancel the execution of the actionthe Action to schedule action, final long time to wait before executing the action; non-positive values indicate an non-delayed
schedule delayTime, final TimeUnit the time unit of unit)delayTimeSchedules an Action for execution at some point in the future. |
| public Subscription | Returns: a subscription to be able to prevent or cancel the execution of the actionthe Action to execute periodically action, long time to wait before executing the action for the first time; non-positive values indicate
an non-delayed schedule initialDelay, long the time interval to wait each time in between executing the action; non-positive values
indicate no delay between repeated schedules period, TimeUnit the time unit of unit)periodSchedules a cancelable action to be executed periodically. |
| Worker | back to summary |
|---|---|
| public Worker() | |
| now | back to summary |
|---|---|
| public long now() Gets the current time, in milliseconds, according to this Scheduler.
| |
| schedule | back to summary |
|---|---|
| public abstract Subscription schedule(Action0 action) Schedules an Action for execution.
| |
| schedule | back to summary |
|---|---|
| public abstract Subscription schedule(final Action0 action, final long delayTime, final TimeUnit unit) Schedules an Action for execution at some point in the future.
Note to implementors: non-positive
| |
| schedulePeriodically | back to summary |
|---|---|
| public Subscription schedulePeriodically(final Action0 action, long initialDelay, long period, TimeUnit unit) Schedules a cancelable action to be executed periodically. This default implementation schedules recursively and waits for actions to complete (instead of potentially executing long-running actions concurrently). Each scheduler that can do periodic scheduling in a better way should override this.
Note to implementors: non-positive
| |