public final class BlockingScheduler extends Scheduler
Use the execute() to start waiting for tasks (from other
threads) or execute(Action) to start with a first action.
public static void main(String[] args) {
BlockingScheduler scheduler = new BlockingScheduler();
scheduler.execute(() -> {
// This executes in the blocking event loop.
// Usually the rest of the "main" method should
// be moved here.
someApi.methodCall()
.subscribeOn(Schedulers.io())
.observeOn(scheduler)
.subscribe(v -> { /* on the main thread */ });
});
}
In the example code above, observeOn(scheduler) will execute
on the main thread of the Java application.Scheduler.Worker| Constructor and Description |
|---|
BlockingScheduler() |
| Modifier and Type | Method and Description |
|---|---|
Scheduler.Worker |
createWorker() |
void |
execute()
Begin executing the blocking event loop without any initial action.
|
void |
execute(Action action)
Begin executing the blocking event loop with the given initial action
(usually contain the rest of the 'main' method).
|
Disposable |
scheduleDirect(Runnable run,
long delay,
TimeUnit unit) |
void |
shutdown() |
clockDriftTolerance, now, scheduleDirect, schedulePeriodicallyDirect, start, whenpublic void execute()
This method will block until the shutdown() is invoked.
execute(Action)public void execute(Action action)
This method will block until the shutdown() is invoked.
action - the action to executepublic Disposable scheduleDirect(Runnable run, long delay, TimeUnit unit)
scheduleDirect in class Schedulerpublic Scheduler.Worker createWorker()
createWorker in class Scheduler