Do small Calculation Task in Background Using RxJava in Most Efficient Way

If you want to use RxJava you get to leverage non-blocking by composing multiple operations in Observables. There are plenty of tutorials out there to help. To answer your question though using RxJava 1:

Completable
    .fromRunnable(() -> doSomething())
    .doOnError(e -> log.error(e.getMessage(), e))
    .subscribeOn(Schedulers.computation())
    .subscribe();

If doSomething doesn’t use CPU exclusively then you might choose Schedulers.io() instead of Schedulers.computation().

Leave a Comment